@Test(expected = RuntimeException.class) public void tryCreateTableWithUnsupportedDataTypeShouldThrowRuntimeException() throws SQLException { PrimitiveType unsupported = new PrimitiveType(Type.Repetition.OPTIONAL, PrimitiveType.PrimitiveTypeName.INT96, "unsupported"); MessageType schema = new MessageType("fs", unsupported); String table = "fs"; String location = "file:" + hdfsTemp + "/garmadon_database/fs"; HiveClient hiveClient = new HiveClient(driverName, "jdbc:hive2: hdfsTemp + "/garmadon_database"); hiveClient.createTableIfNotExist(table, schema, location); }
protected void createTableIfNotExist(String table, MessageType schema, String location) throws SQLException { String hiveSchema = schema.getFields().stream().map(field -> { try { return field.getName() + " " + inferHiveType(field); } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.joining(", ")); String tableCreation = "CREATE EXTERNAL TABLE IF NOT EXISTS " + database + "." + table + "(" + hiveSchema + ")" + " PARTITIONED BY (day string)" + " STORED AS PARQUET" + " LOCATION '" + location + "'"; LOGGER.info("Create table {} if not exists", table); execute(tableCreation); }
HiveClient { protected void createTableIfNotExist(String table, MessageType schema, String location) throws SQLException { String hiveSchema = schema.getFields().stream().map(field -> { try { return field.getName() + " " + inferHiveType(field); } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.joining(", ")); String tableCreation = "CREATE EXTERNAL TABLE IF NOT EXISTS " + database + "." + table + "(" + hiveSchema + ")" + " PARTITIONED BY (day string)" + " STORED AS PARQUET" + " LOCATION '" + location + "'"; LOGGER.info("Create table {} if not exists", table); execute(tableCreation); } }
HiveClient { protected void createTableIfNotExist(String table, MessageType schema, String location) throws SQLException { String hiveSchema = schema.getFields().stream().map(field -> { try { return field.getName() + " " + inferHiveType(field); } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.joining(", ")); String tableCreation = "CREATE EXTERNAL TABLE IF NOT EXISTS " + database + "." + table + "(" + hiveSchema + ")" + " PARTITIONED BY (day string)" + " STORED AS PARQUET" + " LOCATION '" + location + "'"; LOGGER.info("Create table {} if not exists", table); execute(tableCreation); } HiveClient(String driverName, String jdbcUrl, String database, String location); }
HiveClient { protected void createTableIfNotExist(String table, MessageType schema, String location) throws SQLException { String hiveSchema = schema.getFields().stream().map(field -> { try { return field.getName() + " " + inferHiveType(field); } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.joining(", ")); String tableCreation = "CREATE EXTERNAL TABLE IF NOT EXISTS " + database + "." + table + "(" + hiveSchema + ")" + " PARTITIONED BY (day string)" + " STORED AS PARQUET" + " LOCATION '" + location + "'"; LOGGER.info("Create table {} if not exists", table); execute(tableCreation); } 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 void createTableIfNotExist(String table, MessageType schema, String location) throws SQLException { String hiveSchema = schema.getFields().stream().map(field -> { try { return field.getName() + " " + inferHiveType(field); } catch (Exception e) { throw new RuntimeException(e); } }).collect(Collectors.joining(", ")); String tableCreation = "CREATE EXTERNAL TABLE IF NOT EXISTS " + database + "." + table + "(" + hiveSchema + ")" + " PARTITIONED BY (day string)" + " STORED AS PARQUET" + " LOCATION '" + location + "'"; LOGGER.info("Create table {} if not exists", table); execute(tableCreation); } 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();  }