private boolean tryAdvancePastEndBracket() { skipWhitespace(); if (schema.charAt(pos) == '>') { pos++; return true; } return false; }
private boolean tryAdvancePastEndBracket() { skipWhitespace(); if (schema.charAt(pos) == '>') { pos++; return true; } return false; }
private void advancePastComma(String errMsg) throws IOException { skipWhitespace(); expectChar(',', errMsg); skipWhitespace(); }
private void advancePastComma(String errMsg) throws IOException { skipWhitespace(); expectChar(',', errMsg); skipWhitespace(); }
private void expectWhitespace(String errMsg) throws IOException { errorIf(!Character.isWhitespace(schema.charAt(pos)), errMsg); skipWhitespace(); }
private void expectWhitespace(String errMsg) throws IOException { errorIf(!Character.isWhitespace(schema.charAt(pos)), errMsg); skipWhitespace(); }
private Schema parseArray() throws IOException { expectChar('<', "array must be followed by a '<'"); skipWhitespace(); Schema componentType = parseType(); skipWhitespace(); expectChar('>', "array must end with a '>'"); return Schema.arrayOf(componentType); }
private Schema parseArray() throws IOException { expectChar('<', "array must be followed by a '<'"); skipWhitespace(); Schema componentType = parseType(); skipWhitespace(); expectChar('>', "array must end with a '>'"); return Schema.arrayOf(componentType); }
private Schema parseMap() throws IOException { expectChar('<', "map must be followed by a '<'"); skipWhitespace(); Schema keyType = parseType(); // key and value must be separated by a comma advancePastComma("Expected a comma separating map key and value types"); Schema valueType = parseType(); skipWhitespace(); expectChar('>', "map must end with a '>'"); return Schema.mapOf(keyType, valueType); }
private Schema parseMap() throws IOException { expectChar('<', "map must be followed by a '<'"); skipWhitespace(); Schema keyType = parseType(); // key and value must be separated by a comma advancePastComma("Expected a comma separating map key and value types"); Schema valueType = parseType(); skipWhitespace(); expectChar('>', "map must end with a '>'"); return Schema.mapOf(keyType, valueType); }
private Schema parseUnion() throws IOException { expectChar('<', "union must be followed by a '<'"); skipWhitespace(); List<Schema> unionTypes = new ArrayList<>(); // keep going until we see the closing '>' while (true) { unionTypes.add(parseType()); if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating union types"); } return Schema.unionOf(unionTypes); }
private Schema parseUnion() throws IOException { expectChar('<', "union must be followed by a '<'"); skipWhitespace(); List<Schema> unionTypes = new ArrayList<>(); // keep going until we see the closing '>' while (true) { unionTypes.add(parseType()); if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating union types"); } return Schema.unionOf(unionTypes); }
skipWhitespace(); if (schema.startsWith("not null", pos)) { pos += 8;
skipWhitespace(); if (schema.startsWith("not null", pos)) { pos += 8;
public Schema parse() throws IOException { try { List<Schema.Field> fields = new ArrayList<>(); while (pos < end) { String name = nextToken(); expectWhitespace("Expecting whitespace between column name and type"); skipWhitespace(); errorIf(pos >= end, "Unexpected EOF"); fields.add(Schema.Field.of(name, parseType())); // stop if we're at the last field if (pos >= end) { break; } advancePastComma("Expected a comma separating schema columns"); } return Schema.recordOf("rec", fields); } catch (Exception e) { if (e instanceof IOException) { throw e; } // can happen if, for example, there are multiple fields in a record with the same name throw new IOException(e); } }
public Schema parse() throws IOException { try { List<Schema.Field> fields = new ArrayList<>(); while (pos < end) { String name = nextToken(); expectWhitespace("Expecting whitespace between column name and type"); skipWhitespace(); errorIf(pos >= end, "Unexpected EOF"); fields.add(Schema.Field.of(name, parseType())); // stop if we're at the last field if (pos >= end) { break; } advancePastComma("Expected a comma separating schema columns"); } return Schema.recordOf("rec", fields); } catch (Exception e) { if (e instanceof IOException) { throw e; } // can happen if, for example, there are multiple fields in a record with the same name throw new IOException(e); } }
private Schema parseRecord() throws IOException { expectChar('<', "record must be followed with a '<'"); skipWhitespace(); String recordName = "rec" + recordNum; recordNum++; List<Schema.Field> fields = new ArrayList<>(); // keep going until we get to the enclosing '>' while (true) { // colName:type String colName = nextToken(); errorIf(schema.charAt(pos) != ':', "Expecting a ':' between field name and type"); pos++; errorIf(pos >= end, "Unexpected EOF"); fields.add(Schema.Field.of(colName, parseType())); // must be at the end or at a comma if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating record fields"); } return Schema.recordOf(recordName, fields); }
private Schema parseRecord() throws IOException { expectChar('<', "record must be followed with a '<'"); skipWhitespace(); String recordName = "rec" + recordNum; recordNum++; List<Schema.Field> fields = new ArrayList<>(); // keep going until we get to the enclosing '>' while (true) { // colName:type String colName = nextToken(); errorIf(schema.charAt(pos) != ':', "Expecting a ':' between field name and type"); pos++; errorIf(pos >= end, "Unexpected EOF"); fields.add(Schema.Field.of(colName, parseType())); // must be at the end or at a comma if (tryAdvancePastEndBracket()) { break; } advancePastComma("Expected a comma separating record fields"); } return Schema.recordOf(recordName, fields); }