### Question:
KuduTableGenerator { public KuduTable builTable(String ontologyName, String schema, Map<String, String> config) { log.debug("generate kudu table for ontology " + ontologyName); final JSONObject schemaObj = new JSONObject(schema); final JSONObject props = getProperties(schemaObj); final List<String> requiredProps = getRequiredProps(schemaObj); if (props.length() == 1 && ((JSONObject) props.get(requiredProps.get(0))).has("$ref") && ((JSONObject) props.get(requiredProps.get(0))).has("type")) { log.error("Error in the type of properties"); throw new DBPersistenceException( "In KUDU ontology, the properties must be primitive, geometry or timestamp"); } else { return build(ontologyName, props, requiredProps, config); } }  KuduTable builTable(String ontologyName, String schema, Map<String, String> config); JSONObject getProperties(JSONObject jsonObj); List<String> getRequiredProps(JSONObject jsonObj); KuduTable build(String name, JSONObject props, List<String> requiredProperties, Map<String, String> cmap); boolean isPrimitive(JSONObject o); boolean isGeometry(JSONObject o); boolean isTimestamp(JSONObject o); List<HiveColumn> pickType(String key, JSONObject o, List<String> requiredProperties); String pickPrimitiveType(String key, JSONObject o); HiveColumn getPrimaryId(); List<HiveColumn> getContexDataFields();  }### Answer:
@Test public void given_primitive_types__without_root_field_builTable() throws IOException { String schema = FileUtil.getFileContent(FOLDER_PATH + "kudutable_primitive_types_without_root_schema.json"); KuduTable table = kuduTableGenerator.builTable(ONTOLOGY_NAME, schema, null); List<HiveColumn> columns = table.getColumns(); Map<String, String> columnTypes = table.getColumns().stream() .collect(Collectors.toMap(x -> x.getName(), x -> x.getColumnType())); Assert.assertEquals(HiveFieldType.STRING_FIELD, columnTypes.get("field1")); Assert.assertEquals(HiveFieldType.FLOAT_FIELD, columnTypes.get("field2")); Assert.assertEquals(HiveFieldType.BOOLEAN_FIELD, columnTypes.get("field3")); Assert.assertEquals(HiveFieldType.INTEGER_FIELD, columnTypes.get("field4")); Assert.assertEquals(ONTOLOGY_NAME, table.getName()); Assert.assertNotNull(columnTypes.get(JsonFieldType.PRIMARY_ID_FIELD)); Assert.assertEquals(13, columns.size()); }
@Test public void given_complex_types_builTable() throws IOException { String schema = FileUtil.getFileContent(FOLDER_PATH + "kudutable_complex_types_schema.json"); KuduTable table = kuduTableGenerator.builTable(ONTOLOGY_NAME, schema, null); List<HiveColumn> columns = table.getColumns(); Map<String, String> columnTypes = table.getColumns().stream() .collect(Collectors.toMap(x -> x.getName(), x -> x.getColumnType())); Assert.assertEquals(HiveFieldType.DOUBLE_FIELD, columnTypes.get("city" + HiveFieldType.LATITUDE_FIELD)); Assert.assertEquals(HiveFieldType.DOUBLE_FIELD, columnTypes.get("city" + HiveFieldType.LONGITUDE_FIELD)); Assert.assertEquals(HiveFieldType.TIMESTAMP_FIELD, columnTypes.get("created_date")); Assert.assertEquals(ONTOLOGY_NAME, table.getName()); Assert.assertNotNull(columnTypes.get(JsonFieldType.PRIMARY_ID_FIELD)); Assert.assertEquals(12, columns.size()); }