### Question:
SchemaConverter { public String toHiveSchema(Type type) throws UnsupportedTypeException { return toHiveSchema(schemaGenerator.generate(type, false)); } SchemaConverter(boolean escapeColumns); String toHiveSchema(Type type); String toHiveSchema(Schema schema);  }### Answer:
@Test public void testHiveSchemaFor() throws Exception { SchemaConverter schemaConverter = new SchemaConverter(false); Assert.assertEquals("(a int, b bigint, c boolean, d float, e double, f string, g binary, " + "h array<string>, i array<boolean>, j map<int,string>)", schemaConverter.toHiveSchema(Record.class)); Assert.assertEquals("(key string, value struct<ints:array<int>,name:string>)", schemaConverter.toHiveSchema(KeyValue.class)); Assert.assertEquals("(i3 int, record2 struct<" + "record:struct<a:int,b:bigint,c:boolean,d:float,e:double,f:string,g:binary," + "h:array<string>,i:array<boolean>,j:map<int,string>>," + "s2:string>)", schemaConverter.toHiveSchema(Record3.class)); schemaConverter = new SchemaConverter(true); Assert.assertEquals("(`a` int, `b` bigint, `c` boolean, `d` float, `e` double, `f` string, `g` binary, " + "`h` array<string>, `i` array<boolean>, `j` map<int,string>)", schemaConverter.toHiveSchema(Record.class)); Assert.assertEquals("(`key` string, `value` struct<`ints`:array<int>,`name`:string>)", schemaConverter.toHiveSchema(KeyValue.class)); Assert.assertEquals("(`i3` int, `record2` struct<" + "`record`:struct<`a`:int,`b`:bigint,`c`:boolean,`d`:float,`e`:double,`f`:string,`g`:binary," + "`h`:array<string>,`i`:array<boolean>,`j`:map<int,string>>," + "`s2`:string>)", schemaConverter.toHiveSchema(Record3.class)); }
@Test public void testBacktickInFieldName() throws Exception { Schema schema = Schema.recordOf( "backtick", Schema.Field.of("abc`123", Schema.of(Schema.Type.STRING)), Schema.Field.of("re`c", Schema.recordOf( "record", Schema.Field.of("`x", Schema.of(Schema.Type.INT)))) ); SchemaConverter schemaConverter = new SchemaConverter(false); Assert.assertEquals("(abc`123 string, re`c struct<`x:int>)", schemaConverter.toHiveSchema(schema)); schemaConverter = new SchemaConverter(true); Assert.assertEquals("(`abc``123` string, `re``c` struct<```x`:int>)", schemaConverter.toHiveSchema(schema)); }
@Test public void testSupportedTypes() throws Exception { new SchemaConverter(false).toHiveSchema(NotRecursive.class); new SchemaConverter(true).toHiveSchema(NotRecursive.class); }
@Test public void testDateTimestampType() throws Exception { Schema schema = Schema.recordOf( "schema", Schema.Field.of("id", Schema.of(Schema.Type.INT)), Schema.Field.of("record", Schema.recordOf( "record", Schema.Field.of("name", Schema.of(Schema.Type.STRING)), Schema.Field.of("dt", Schema.of(Schema.LogicalType.DATE)), Schema.Field.of("ts1", Schema.of(Schema.LogicalType.TIMESTAMP_MILLIS)), Schema.Field.of("ts2", Schema.of(Schema.LogicalType.TIMESTAMP_MICROS)))) ); SchemaConverter schemaConverter = new SchemaConverter(false); Assert.assertEquals("(id int, record struct<name:string,dt:date,ts1:timestamp,ts2:timestamp>)", schemaConverter.toHiveSchema(schema)); }