@Test public void testLogicalType() throws Exception { Row testRow = new Row(); testRow.add("id", 1); testRow.add("name", "abc"); testRow.add("date", LocalDate.of(2018, 11, 11)); testRow.add("time", LocalTime.of(11, 11, 11)); testRow.add("timestamp", ZonedDateTime.of(2018, 11 , 11 , 11, 11, 11, 0, ZoneId.of("UTC"))); testRow.add("d", new BigDecimal(new BigInteger("123456"), 5)); Json2Schema json2Schema = new Json2Schema(); Schema actual = json2Schema.toSchema("testRecord", testRow); Schema expected = Schema.recordOf("testRecord", Schema.Field.of("id", Schema.nullableOf(Schema.of(Schema.Type.INT))), Schema.Field.of("name", Schema.nullableOf(Schema.of(Schema.Type.STRING))), Schema.Field.of("date", Schema.nullableOf(Schema.of(Schema.LogicalType.DATE))), Schema.Field.of("time", Schema.nullableOf( Schema.of(Schema.LogicalType.TIME_MICROS))), Schema.Field.of("timestamp", Schema.nullableOf( Schema.of(Schema.LogicalType.TIMESTAMP_MICROS))), Schema.Field.of("d", Schema.nullableOf(Schema.decimalOf(38, 5)))); Assert.assertEquals(expected, actual); }
public Schema toSchema(String id, Row row) throws RecordConvertorException { List<Schema.Field> fields = new ArrayList<>(); for (Pair<String, Object> column : row.getFields()) { String name = column.getFirst(); Object value = column.getSecond(); if (value instanceof Schema) { fields.addAll(((Schema) value).getFields()); } else { Schema schema = getSchema(value, name); if (schema != null) { fields.add(Schema.Field.of(name, schema)); } } } return Schema.recordOf(id, fields); }
Json2Schema { public Schema toSchema(String id, Row row) throws RecordConvertorException { List<Schema.Field> fields = new ArrayList<>(); for (Pair<String, Object> column : row.getFields()) { String name = column.getFirst(); Object value = column.getSecond(); if (value instanceof Schema) { fields.addAll(((Schema) value).getFields()); } else { Schema schema = getSchema(value, name); if (schema != null) { fields.add(Schema.Field.of(name, schema)); } } } return Schema.recordOf(id, fields); } }
Json2Schema { public Schema toSchema(String id, Row row) throws RecordConvertorException { List<Schema.Field> fields = new ArrayList<>(); for (Pair<String, Object> column : row.getFields()) { String name = column.getFirst(); Object value = column.getSecond(); if (value instanceof Schema) { fields.addAll(((Schema) value).getFields()); } else { Schema schema = getSchema(value, name); if (schema != null) { fields.add(Schema.Field.of(name, schema)); } } } return Schema.recordOf(id, fields); } Json2Schema(); }
Json2Schema { public Schema toSchema(String id, Row row) throws RecordConvertorException { List<Schema.Field> fields = new ArrayList<>(); for (Pair<String, Object> column : row.getFields()) { String name = column.getFirst(); Object value = column.getSecond(); if (value instanceof Schema) { fields.addAll(((Schema) value).getFields()); } else { Schema schema = getSchema(value, name); if (schema != null) { fields.add(Schema.Field.of(name, schema)); } } } return Schema.recordOf(id, fields); } Json2Schema(); Schema toSchema(String id, Row row); }
Json2Schema { public Schema toSchema(String id, Row row) throws RecordConvertorException { List<Schema.Field> fields = new ArrayList<>(); for (Pair<String, Object> column : row.getFields()) { String name = column.getFirst(); Object value = column.getSecond(); if (value instanceof Schema) { fields.addAll(((Schema) value).getFields()); } else { Schema schema = getSchema(value, name); if (schema != null) { fields.add(Schema.Field.of(name, schema)); } } } return Schema.recordOf(id, fields); } Json2Schema(); Schema toSchema(String id, Row row);  }