Java Code Examples for org.apache.hadoop.hive.metastore.api.StorageDescriptor#setOutputFormat()
The following examples show how to use
org.apache.hadoop.hive.metastore.api.StorageDescriptor#setOutputFormat() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalogToHiveConverter.java From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 | 6 votes |
public static StorageDescriptor convertStorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor catalogSd) { StorageDescriptor hiveSd = new StorageDescriptor(); hiveSd.setCols(convertFieldSchemaList(catalogSd.getColumns())); hiveSd.setLocation(catalogSd.getLocation()); hiveSd.setInputFormat(catalogSd.getInputFormat()); hiveSd.setOutputFormat(catalogSd.getOutputFormat()); hiveSd.setCompressed(catalogSd.getCompressed()); hiveSd.setNumBuckets(catalogSd.getNumberOfBuckets()); hiveSd.setSerdeInfo(convertSerDeInfo(catalogSd.getSerdeInfo())); hiveSd.setBucketCols(firstNonNull(catalogSd.getBucketColumns(), Lists.<String>newArrayList())); hiveSd.setSortCols(convertOrderList(catalogSd.getSortColumns())); hiveSd.setParameters(firstNonNull(catalogSd.getParameters(), Maps.<String, String>newHashMap())); hiveSd.setSkewedInfo(convertSkewedInfo(catalogSd.getSkewedInfo())); hiveSd.setStoredAsSubDirectories(catalogSd.getStoredAsSubDirectories()); return hiveSd; }
Example 2
Source File: TestUtils.java From circus-train with Apache License 2.0 | 5 votes |
public static Partition newPartition(String database, String tableName, String partitionValue) { Partition partition = new Partition(); partition.setDbName(database); partition.setTableName(tableName); partition.setCreateTime(CREATE_TIME); partition.setValues(ImmutableList.of(partitionValue)); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); partition.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(COLS); storageDescriptor.setInputFormat(INPUT_FORMAT); storageDescriptor.setOutputFormat(OUTPUT_FORMAT); storageDescriptor.setSerdeInfo(new SerDeInfo(SERDE_INFO_NAME, SERIALIZATION_LIB, new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation(DATABASE + "/" + tableName + "/" + partitionValue + "/"); partition.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); partition.setParameters(parameters); return partition; }
Example 3
Source File: TestPutHive3Streaming.java From nifi with Apache License 2.0 | 5 votes |
MockHiveStreamingConnection(HiveOptions options, RecordReader reader, RecordWriter recordWriter, List<FieldSchema> schema) throws StreamingException { this.options = options; metastoreURI = options.getMetaStoreURI(); this.writer = recordWriter; this.hiveConf = this.options.getHiveConf(); connectionStats = new ConnectionStats(); this.table = new Table(Table.getEmptyTable(options.getDatabaseName(), options.getTableName())); this.table.setFields(schema); StorageDescriptor sd = this.table.getSd(); sd.setOutputFormat(OrcOutputFormat.class.getName()); sd.setLocation(TARGET_HIVE); }
Example 4
Source File: HiveMetaStoreUtils.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private static StorageDescriptor getStorageDescriptor(HiveRegistrationUnit unit) { State props = unit.getStorageProps(); StorageDescriptor sd = new StorageDescriptor(); sd.setParameters(getParameters(props)); //Treat AVRO and other formats differently. Details can be found in GOBBLIN-877 if (unit.isRegisterSchema() || (unit.getInputFormat().isPresent() && !unit.getInputFormat().get().equals(AvroContainerInputFormat.class.getName()))) { sd.setCols(getFieldSchemas(unit)); } if (unit.getLocation().isPresent()) { sd.setLocation(unit.getLocation().get()); } if (unit.getInputFormat().isPresent()) { sd.setInputFormat(unit.getInputFormat().get()); } if (unit.getOutputFormat().isPresent()) { sd.setOutputFormat(unit.getOutputFormat().get()); } if (unit.getIsCompressed().isPresent()) { sd.setCompressed(unit.getIsCompressed().get()); } if (unit.getNumBuckets().isPresent()) { sd.setNumBuckets(unit.getNumBuckets().get()); } if (unit.getBucketColumns().isPresent()) { sd.setBucketCols(unit.getBucketColumns().get()); } if (unit.getIsStoredAsSubDirs().isPresent()) { sd.setStoredAsSubDirectories(unit.getIsStoredAsSubDirs().get()); } sd.setSerdeInfo(getSerDeInfo(unit)); return sd; }
Example 5
Source File: HiveTableMetaStoreFactory.java From flink with Apache License 2.0 | 5 votes |
private void alterPartition(LinkedHashMap<String, String> partitionSpec, Path partitionPath, Partition currentPartition) throws Exception { StorageDescriptor partSD = currentPartition.getSd(); // the following logic copied from Hive::alterPartitionSpecInMemory partSD.setOutputFormat(sd.getOutputFormat()); partSD.setInputFormat(sd.getInputFormat()); partSD.getSerdeInfo().setSerializationLib(sd.getSerdeInfo().getSerializationLib()); partSD.getSerdeInfo().setParameters(sd.getSerdeInfo().getParameters()); partSD.setBucketCols(sd.getBucketCols()); partSD.setNumBuckets(sd.getNumBuckets()); partSD.setSortCols(sd.getSortCols()); partSD.setLocation(partitionPath.toString()); client.alter_partition(database, tableName, currentPartition); }
Example 6
Source File: HiveTableUtil.java From flink with Apache License 2.0 | 5 votes |
public static void setStorageFormat(StorageDescriptor sd, String format, HiveConf hiveConf) { StorageFormatDescriptor storageFormatDescriptor = storageFormatFactory.get(format); checkArgument(storageFormatDescriptor != null, "Unknown storage format " + format); sd.setInputFormat(storageFormatDescriptor.getInputFormat()); sd.setOutputFormat(storageFormatDescriptor.getOutputFormat()); String serdeLib = storageFormatDescriptor.getSerde(); if (serdeLib == null && storageFormatDescriptor instanceof RCFileStorageFormatDescriptor) { serdeLib = hiveConf.getVar(HiveConf.ConfVars.HIVEDEFAULTRCFILESERDE); } if (serdeLib != null) { sd.getSerdeInfo().setSerializationLib(serdeLib); } }
Example 7
Source File: HiveTableUtil.java From flink with Apache License 2.0 | 5 votes |
private static void extractStoredAs(StorageDescriptor sd, Map<String, String> properties, HiveConf hiveConf) { String storageFormat = properties.remove(STORED_AS_FILE_FORMAT); String inputFormat = properties.remove(STORED_AS_INPUT_FORMAT); String outputFormat = properties.remove(STORED_AS_OUTPUT_FORMAT); if (storageFormat == null && inputFormat == null) { return; } if (storageFormat != null) { setStorageFormat(sd, storageFormat, hiveConf); } else { sd.setInputFormat(inputFormat); sd.setOutputFormat(outputFormat); } }
Example 8
Source File: HiveConnectorPartitionService.java From metacat with Apache License 2.0 | 5 votes |
private void copyTableSdToPartitionSd(final List<Partition> hivePartitions, final Table table) { // // Update the partition info based on that of the table. // for (Partition partition : hivePartitions) { final StorageDescriptor sd = partition.getSd(); final StorageDescriptor tableSdCopy = table.getSd().deepCopy(); if (tableSdCopy.getSerdeInfo() == null) { final SerDeInfo serDeInfo = new SerDeInfo(null, null, new HashMap<>()); tableSdCopy.setSerdeInfo(serDeInfo); } tableSdCopy.setLocation(sd.getLocation()); if (!Strings.isNullOrEmpty(sd.getInputFormat())) { tableSdCopy.setInputFormat(sd.getInputFormat()); } if (!Strings.isNullOrEmpty(sd.getOutputFormat())) { tableSdCopy.setOutputFormat(sd.getOutputFormat()); } if (sd.getParameters() != null && !sd.getParameters().isEmpty()) { tableSdCopy.setParameters(sd.getParameters()); } if (sd.getSerdeInfo() != null) { if (!Strings.isNullOrEmpty(sd.getSerdeInfo().getName())) { tableSdCopy.getSerdeInfo().setName(sd.getSerdeInfo().getName()); } if (!Strings.isNullOrEmpty(sd.getSerdeInfo().getSerializationLib())) { tableSdCopy.getSerdeInfo().setSerializationLib(sd.getSerdeInfo().getSerializationLib()); } if (sd.getSerdeInfo().getParameters() != null && !sd.getSerdeInfo().getParameters().isEmpty()) { tableSdCopy.getSerdeInfo().setParameters(sd.getSerdeInfo().getParameters()); } } partition.setSd(tableSdCopy); } }
Example 9
Source File: PartitionTransformationTest.java From circus-train with Apache License 2.0 | 5 votes |
@Before public void init() { partition = new Partition(); partition.setDbName("database"); partition.setTableName("table"); partition.setValues(ImmutableList.of("part")); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); partition.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(Arrays.asList(new FieldSchema("a", "int", null))); storageDescriptor.setInputFormat("input_format"); storageDescriptor.setOutputFormat("output_format"); storageDescriptor.setSerdeInfo(new SerDeInfo("serde", "lib", new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation("database/table/part/"); partition.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); partition.setParameters(parameters); }
Example 10
Source File: TableTransformationTest.java From circus-train with Apache License 2.0 | 5 votes |
@Before public void init() { table = new Table(); table.setDbName("database"); table.setTableName("table"); table.setTableType("type"); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); table.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(Arrays.asList(new FieldSchema("a", "int", null))); storageDescriptor.setInputFormat("input_format"); storageDescriptor.setOutputFormat("output_format"); storageDescriptor.setSerdeInfo(new SerDeInfo("serde", "lib", new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation("database/table/"); table.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); table.setParameters(parameters); }
Example 11
Source File: TestUtils.java From circus-train with Apache License 2.0 | 5 votes |
public static Table newTable(String database, String tableName) { Table table = new Table(); table.setDbName(database); table.setTableName(tableName); table.setTableType(TABLE_TYPE); table.setOwner(OWNER); table.setCreateTime(CREATE_TIME); table.setRetention(RETENTION); Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>(); userPrivileges.put("read", ImmutableList.of(new PrivilegeGrantInfo())); PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet(); privileges.setUserPrivileges(userPrivileges); table.setPrivileges(privileges); StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setCols(COLS); storageDescriptor.setInputFormat(INPUT_FORMAT); storageDescriptor.setOutputFormat(OUTPUT_FORMAT); storageDescriptor.setSerdeInfo(new SerDeInfo(SERDE_INFO_NAME, SERIALIZATION_LIB, new HashMap<String, String>())); storageDescriptor.setSkewedInfo(new SkewedInfo()); storageDescriptor.setParameters(new HashMap<String, String>()); storageDescriptor.setLocation(DATABASE + "/" + tableName + "/"); table.setSd(storageDescriptor); Map<String, String> parameters = new HashMap<>(); parameters.put("com.company.parameter", "abc"); table.setParameters(parameters); return table; }
Example 12
Source File: TestUtils.java From circus-train with Apache License 2.0 | 5 votes |
public static Table createUnpartitionedTable( HiveMetaStoreClient metaStoreClient, String database, String table, URI location) throws TException { Table hiveTable = new Table(); hiveTable.setDbName(database); hiveTable.setTableName(table); hiveTable.setTableType(TableType.EXTERNAL_TABLE.name()); hiveTable.putToParameters("EXTERNAL", "TRUE"); StorageDescriptor sd = new StorageDescriptor(); sd.setCols(DATA_COLUMNS); sd.setLocation(location.toString()); sd.setParameters(new HashMap<String, String>()); sd.setInputFormat(TextInputFormat.class.getName()); sd.setOutputFormat(TextOutputFormat.class.getName()); sd.setSerdeInfo(new SerDeInfo()); sd.getSerdeInfo().setSerializationLib("org.apache.hadoop.hive.serde2.OpenCSVSerde"); hiveTable.setSd(sd); metaStoreClient.createTable(hiveTable); ColumnStatisticsDesc statsDesc = new ColumnStatisticsDesc(true, database, table); ColumnStatisticsData statsData = new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1L, 2L)); ColumnStatisticsObj cso1 = new ColumnStatisticsObj("id", "bigint", statsData); List<ColumnStatisticsObj> statsObj = Collections.singletonList(cso1); metaStoreClient.updateTableColumnStatistics(new ColumnStatistics(statsDesc, statsObj)); return hiveTable; }
Example 13
Source File: HiveCatalog.java From flink with Apache License 2.0 | 5 votes |
private static void setStorageFormat(StorageDescriptor sd, Map<String, String> properties) { // TODO: allow user to specify storage format. Simply use text format for now String storageFormatName = DEFAULT_HIVE_TABLE_STORAGE_FORMAT; StorageFormatDescriptor storageFormatDescriptor = storageFormatFactory.get(storageFormatName); checkArgument(storageFormatDescriptor != null, "Unknown storage format " + storageFormatName); sd.setInputFormat(storageFormatDescriptor.getInputFormat()); sd.setOutputFormat(storageFormatDescriptor.getOutputFormat()); String serdeLib = storageFormatDescriptor.getSerde(); sd.getSerdeInfo().setSerializationLib(serdeLib != null ? serdeLib : LazySimpleSerDe.class.getName()); }
Example 14
Source File: ThriftMetastoreUtil.java From presto with Apache License 2.0 | 5 votes |
private static StorageDescriptor makeStorageDescriptor(String tableName, List<Column> columns, Storage storage) { SerDeInfo serdeInfo = new SerDeInfo(); serdeInfo.setName(tableName); serdeInfo.setSerializationLib(storage.getStorageFormat().getSerDeNullable()); serdeInfo.setParameters(storage.getSerdeParameters()); StorageDescriptor sd = new StorageDescriptor(); sd.setLocation(emptyToNull(storage.getLocation())); sd.setCols(columns.stream() .map(ThriftMetastoreUtil::toMetastoreApiFieldSchema) .collect(toImmutableList())); sd.setSerdeInfo(serdeInfo); sd.setInputFormat(storage.getStorageFormat().getInputFormatNullable()); sd.setOutputFormat(storage.getStorageFormat().getOutputFormatNullable()); sd.setSkewedInfoIsSet(storage.isSkewed()); sd.setParameters(ImmutableMap.of()); Optional<HiveBucketProperty> bucketProperty = storage.getBucketProperty(); if (bucketProperty.isPresent()) { sd.setNumBuckets(bucketProperty.get().getBucketCount()); sd.setBucketCols(bucketProperty.get().getBucketedBy()); if (!bucketProperty.get().getSortedBy().isEmpty()) { sd.setSortCols(bucketProperty.get().getSortedBy().stream() .map(column -> new Order(column.getColumnName(), column.getOrder().getHiveOrder())) .collect(toImmutableList())); } } return sd; }
Example 15
Source File: AvroStorageDescriptorFactory.java From data-highway with Apache License 2.0 | 5 votes |
public static StorageDescriptor create(String location) { StorageDescriptor storageDescriptor = new StorageDescriptor(); storageDescriptor.setInputFormat(AVRO_INPUT_FORMAT); storageDescriptor.setOutputFormat(AVRO_OUTPUT_FORMAT); storageDescriptor.setLocation(location); storageDescriptor.setCols(emptyList()); SerDeInfo serdeInfo = new SerDeInfo(); serdeInfo.setSerializationLib(AVRO_SERDE); storageDescriptor.setSerdeInfo(serdeInfo); return storageDescriptor; }
Example 16
Source File: MetaStoreRestApiTest.java From submarine with Apache License 2.0 | 4 votes |
@Before public void createDatabase() { Database database = new Database(); database.setName("testdb"); database.setDescription("testdb"); database.setLocationUri("hdfs://mycluster/user/hive/warehouse/testdb.db"); Map<String, String> map = new HashMap<>(); map.put("key", "value"); database.setParameters(map); database.setOwnerName("root"); database.setOwnerType(PrincipalType.USER); Gson gson = new Gson(); String databaseJson = gson.toJson(database); metaStoreApi.createDatabase(databaseJson); Response databaseCountResponse = metaStoreApi.getDatabaseCount(); assertEquals(databaseCountResponse.getStatus(), Response.Status.OK.getStatusCode()); assertTrue(((String) databaseCountResponse.getEntity()).contains("\"result\":1")); Table table = new Table(); table.setTableName("testtable"); table.setDbName("testdb"); table.setOwner("root"); table.setCreateTime((int) new java.util.Date().getTime() / 1000); table.setLastAccessTime((int) new Date().getTime() / 1000); table.setRetention(0); StorageDescriptor sd = new StorageDescriptor(); List<FieldSchema> fieldSchemas = new ArrayList<>(); FieldSchema fieldSchema = new FieldSchema(); fieldSchema.setName("a"); fieldSchema.setType("int"); fieldSchema.setComment("a"); fieldSchemas.add(fieldSchema); sd.setCols(fieldSchemas); sd.setLocation("hdfs://mycluster/user/hive/warehouse/testdb.db/testtable"); sd.setInputFormat("org.apache.hadoop.mapred.TextInputFormat"); sd.setOutputFormat("org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"); sd.setCompressed(false); sd.setNumBuckets(-1); SerDeInfo serdeInfo = new SerDeInfo(); serdeInfo.setName("test"); serdeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"); Map<String, String> parametersMap = new HashMap<>(); parametersMap.put("serialization.format", "|"); parametersMap.put("field.delim", "|"); serdeInfo.setParameters(parametersMap); sd.setSerdeInfo(serdeInfo); table.setSd(sd); List<FieldSchema> partitionKeys = new ArrayList<>(); table.setPartitionKeys(partitionKeys); Map<String, String> parameters = new HashMap<>(); table.setParameters(parameters); String viewOriginalText = ""; table.setViewOriginalText(viewOriginalText); String viewExpandedText = ""; table.setViewExpandedText(viewExpandedText); String tableType = "MANAGED_TABLE"; table.setTableType(tableType); String tableJson = gson.toJson(table); metaStoreApi.createTable(tableJson); Response tableResponse = metaStoreApi.getTable("testdb", "testtable"); assertEquals(tableResponse.getStatus(), Response.Status.OK.getStatusCode()); assertTrue(((String) tableResponse.getEntity()).contains("\"tableName\":\"testtable\"")); Response tableCountResponse = metaStoreApi.getTableCount(); assertEquals(tableCountResponse.getStatus(), Response.Status.OK.getStatusCode()); assertTrue(((String) tableCountResponse.getEntity()).contains("\"result\":1")); }
Example 17
Source File: TestUtils.java From circus-train with Apache License 2.0 | 4 votes |
public static Table createPartitionedTable( HiveMetaStoreClient metaStoreClient, String database, String table, URI location, List<FieldSchema> columns, List<FieldSchema> partitionKeys, String serializationLib, String inputFormatClassName, String outputFormatClassName) throws Exception { Table hiveTable = new Table(); hiveTable.setDbName(database); hiveTable.setTableName(table); hiveTable.setTableType(TableType.EXTERNAL_TABLE.name()); hiveTable.putToParameters("EXTERNAL", "TRUE"); hiveTable.setPartitionKeys(partitionKeys); StorageDescriptor sd = new StorageDescriptor(); sd.setCols(columns); sd.setLocation(location.toString()); sd.setParameters(new HashMap<String, String>()); sd.setInputFormat(inputFormatClassName); sd.setOutputFormat(outputFormatClassName); sd.setSerdeInfo(new SerDeInfo()); sd.getSerdeInfo().setSerializationLib(serializationLib); hiveTable.setSd(sd); metaStoreClient.createTable(hiveTable); ColumnStatisticsDesc statsDesc = new ColumnStatisticsDesc(true, database, table); ColumnStatisticsData statsData = new ColumnStatisticsData(_Fields.LONG_STATS, new LongColumnStatsData(1L, 2L)); ColumnStatisticsObj cso1 = new ColumnStatisticsObj("id", "bigint", statsData); List<ColumnStatisticsObj> statsObj = Collections.singletonList(cso1); metaStoreClient.updateTableColumnStatistics(new ColumnStatistics(statsDesc, statsObj)); return hiveTable; }
Example 18
Source File: HiveConvertersImpl.java From metacat with Apache License 2.0 | 4 votes |
private StorageDescriptor fromStorageDto(@Nullable final StorageDto storageDto, @Nullable final String serdeName) { // // Set all required fields to null. This is to simulate Hive behavior. // Setting it to empty string failed certain hive operations. // final StorageDescriptor result = new StorageDescriptor(); String inputFormat = null; String location = null; String outputFormat = null; String serializationLib = null; Map<String, String> sdParams = Maps.newHashMap(); Map<String, String> serdeParams = Maps.newHashMap(); if (storageDto != null) { if (storageDto.getInputFormat() != null) { inputFormat = storageDto.getInputFormat(); } if (storageDto.getUri() != null) { location = storageDto.getUri(); } if (storageDto.getOutputFormat() != null) { outputFormat = storageDto.getOutputFormat(); } if (storageDto.getSerializationLib() != null) { serializationLib = storageDto.getSerializationLib(); } if (storageDto.getParameters() != null) { sdParams = storageDto.getParameters(); } if (storageDto.getSerdeInfoParameters() != null) { serdeParams = storageDto.getSerdeInfoParameters(); } } result.setSerdeInfo(new SerDeInfo(serdeName, serializationLib, serdeParams)); result.setBucketCols(Collections.emptyList()); result.setSortCols(Collections.emptyList()); result.setInputFormat(inputFormat); result.setLocation(location); result.setOutputFormat(outputFormat); result.setCols(Collections.emptyList()); // Setting an empty skewed info. result.setSkewedInfo(new SkewedInfo(Collections.emptyList(), Collections.emptyList(), Collections.emptyMap())); result.setParameters(sdParams); return result; }
Example 19
Source File: SubmarineMetaStoreTest.java From submarine with Apache License 2.0 | 4 votes |
@Before public void createDatabase() throws InvalidObjectException, MetaException { listTables(); Database database = new Database(); database.setName("testdb"); database.setDescription("testdb"); database.setLocationUri("hdfs://mycluster/user/hive/warehouse/testdb.db"); Map map = new HashMap(); map.put("key", "value"); database.setParameters(map); database.setOwnerName("root"); database.setOwnerType(PrincipalType.USER); submarineMetaStore.createDatabase(database); assertEquals(1, submarineMetaStore.getDatabaseCount()); Table table = new Table(); table.setTableName("testtable"); table.setDbName("testdb"); table.setOwner("root"); table.setCreateTime((int) new Date().getTime() / 1000); table.setLastAccessTime((int) new Date().getTime() / 1000); table.setRetention(0); StorageDescriptor sd = new StorageDescriptor(); List<FieldSchema> fieldSchemas = new ArrayList<>(); FieldSchema fieldSchema = new FieldSchema(); fieldSchema.setName("a"); fieldSchema.setType("int"); fieldSchema.setComment("a"); fieldSchemas.add(fieldSchema); sd.setCols(fieldSchemas); sd.setLocation("hdfs://mycluster/user/hive/warehouse/testdb.db/testtable"); sd.setInputFormat("org.apache.hadoop.mapred.TextInputFormat"); sd.setOutputFormat("org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"); sd.setCompressed(false); sd.setNumBuckets(-1); SerDeInfo serdeInfo = new SerDeInfo(); serdeInfo.setName("test"); serdeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"); Map<String, String> parametersMap = new HashMap(); parametersMap.put("serialization.format", "|"); parametersMap.put("field.delim", "|"); serdeInfo.setParameters(parametersMap); sd.setSerdeInfo(serdeInfo); table.setSd(sd); List<FieldSchema> partitionKeys = new ArrayList<>(); table.setPartitionKeys(partitionKeys); Map<String, String> parameters = new HashMap<>(); table.setParameters(parameters); String viewOriginalText = ""; table.setViewOriginalText(viewOriginalText); String viewExpandedText = ""; table.setViewExpandedText(viewExpandedText); String tableType = "MANAGED_TABLE"; table.setTableType(tableType); submarineMetaStore.createTable(table); Table tableTest = submarineMetaStore.getTable("testdb", "testtable"); assertEquals("testtable", tableTest.getTableName()); int tableCount = submarineMetaStore.getTableCount(); assertEquals(1, tableCount); }