@Test public void shouldProvideHiveTypeFromParquetType() throws Exception { HiveClient hiveClient = new HiveClient(driverName, "jdbc:hive2: hdfsTemp + "/garmadon_database"); PrimitiveType string = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.BINARY, "name"); assertEquals("string", hiveClient.inferHiveType(string)); PrimitiveType array_string = new PrimitiveType(Type.Repetition.REPEATED, PrimitiveType.PrimitiveTypeName.BINARY, "name"); assertEquals("array<string>", hiveClient.inferHiveType(array_string)); PrimitiveType int32 = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.INT32, "name"); assertEquals("int", hiveClient.inferHiveType(int32)); PrimitiveType int64 = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.INT64, "name"); assertEquals("bigint", hiveClient.inferHiveType(int64)); PrimitiveType floatz = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.FLOAT, "name"); assertEquals("float", hiveClient.inferHiveType(floatz)); PrimitiveType doublez = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.DOUBLE, "name"); assertEquals("double", hiveClient.inferHiveType(doublez)); PrimitiveType booleanz = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.BOOLEAN, "name"); assertEquals("boolean", hiveClient.inferHiveType(booleanz)); }
protected String inferHiveType(Type field) throws Exception { String fieldHiveType; switch (field.asPrimitiveType().getPrimitiveTypeName().name()) { case "BINARY": fieldHiveType = "string"; break; case "INT32": fieldHiveType = "int"; break; case "INT64": fieldHiveType = "bigint"; break; case "FLOAT": fieldHiveType = "float"; break; case "DOUBLE": fieldHiveType = "double"; break; case "BOOLEAN": fieldHiveType = "boolean"; break; default: throw new Exception("Unsupported Data Type: " + field.asPrimitiveType().getPrimitiveTypeName().name()); } if (field.isRepetition(Type.Repetition.REPEATED)) { fieldHiveType = "array<" + fieldHiveType + ">"; } return fieldHiveType; }
HiveClient { protected String inferHiveType(Type field) throws Exception { String fieldHiveType; switch (field.asPrimitiveType().getPrimitiveTypeName().name()) { case "BINARY": fieldHiveType = "string"; break; case "INT32": fieldHiveType = "int"; break; case "INT64": fieldHiveType = "bigint"; break; case "FLOAT": fieldHiveType = "float"; break; case "DOUBLE": fieldHiveType = "double"; break; case "BOOLEAN": fieldHiveType = "boolean"; break; default: throw new Exception("Unsupported Data Type: " + field.asPrimitiveType().getPrimitiveTypeName().name()); } if (field.isRepetition(Type.Repetition.REPEATED)) { fieldHiveType = "array<" + fieldHiveType + ">"; } return fieldHiveType; } }
HiveClient { protected String inferHiveType(Type field) throws Exception { String fieldHiveType; switch (field.asPrimitiveType().getPrimitiveTypeName().name()) { case "BINARY": fieldHiveType = "string"; break; case "INT32": fieldHiveType = "int"; break; case "INT64": fieldHiveType = "bigint"; break; case "FLOAT": fieldHiveType = "float"; break; case "DOUBLE": fieldHiveType = "double"; break; case "BOOLEAN": fieldHiveType = "boolean"; break; default: throw new Exception("Unsupported Data Type: " + field.asPrimitiveType().getPrimitiveTypeName().name()); } if (field.isRepetition(Type.Repetition.REPEATED)) { fieldHiveType = "array<" + fieldHiveType + ">"; } return fieldHiveType; } HiveClient(String driverName, String jdbcUrl, String database, String location); }
HiveClient { protected String inferHiveType(Type field) throws Exception { String fieldHiveType; switch (field.asPrimitiveType().getPrimitiveTypeName().name()) { case "BINARY": fieldHiveType = "string"; break; case "INT32": fieldHiveType = "int"; break; case "INT64": fieldHiveType = "bigint"; break; case "FLOAT": fieldHiveType = "float"; break; case "DOUBLE": fieldHiveType = "double"; break; case "BOOLEAN": fieldHiveType = "boolean"; break; default: throw new Exception("Unsupported Data Type: " + field.asPrimitiveType().getPrimitiveTypeName().name()); } if (field.isRepetition(Type.Repetition.REPEATED)) { fieldHiveType = "array<" + fieldHiveType + ">"; } return fieldHiveType; } HiveClient(String driverName, String jdbcUrl, String database, String location); void createDatabaseIfAbsent(String location); void createPartitionIfNotExist(String table, MessageType schema, String partition, String location); void close(); }
HiveClient { protected String inferHiveType(Type field) throws Exception { String fieldHiveType; switch (field.asPrimitiveType().getPrimitiveTypeName().name()) { case "BINARY": fieldHiveType = "string"; break; case "INT32": fieldHiveType = "int"; break; case "INT64": fieldHiveType = "bigint"; break; case "FLOAT": fieldHiveType = "float"; break; case "DOUBLE": fieldHiveType = "double"; break; case "BOOLEAN": fieldHiveType = "boolean"; break; default: throw new Exception("Unsupported Data Type: " + field.asPrimitiveType().getPrimitiveTypeName().name()); } if (field.isRepetition(Type.Repetition.REPEATED)) { fieldHiveType = "array<" + fieldHiveType + ">"; } return fieldHiveType; } HiveClient(String driverName, String jdbcUrl, String database, String location); void createDatabaseIfAbsent(String location); void createPartitionIfNotExist(String table, MessageType schema, String partition, String location); void close();  }