private Schema parseType() throws IOException { String typeStr = nextToken(); if ("boolean".equals(typeStr)) { type = Schema.of(Schema.Type.BOOLEAN);
private Schema parseType() throws IOException { String typeStr = nextToken(); if ("boolean".equals(typeStr)) { type = Schema.of(Schema.Type.BOOLEAN);
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); }