Java Code Examples for org.apache.hadoop.hive.metastore.HiveMetaStoreClient#listPartitions()
The following examples show how to use
org.apache.hadoop.hive.metastore.HiveMetaStoreClient#listPartitions() .
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: HiveServer2CoreTest.java From beeju with Apache License 2.0 | 6 votes |
@Test public void addPartition() throws Exception { HiveServer2Core server = setupServer(); String tableName = "my_table"; createPartitionedTable(DATABASE, tableName, server); try (Connection connection = DriverManager.getConnection(server.getJdbcConnectionUrl()); Statement statement = connection.createStatement()) { String addPartitionHql = String.format("ALTER TABLE %s.%s ADD PARTITION (partcol=1)", DATABASE, tableName); statement.execute(addPartitionHql); } HiveMetaStoreClient client = server.getCore().newClient(); try { List<Partition> partitions = client.listPartitions(DATABASE, tableName, (short) -1); assertThat(partitions.size(), is(1)); assertThat(partitions.get(0).getDbName(), is(DATABASE)); assertThat(partitions.get(0).getTableName(), is(tableName)); assertThat(partitions.get(0).getValues(), is(Arrays.asList("1"))); assertThat(partitions.get(0).getSd().getLocation(), is(String.format("file:%s/%s/%s/partcol=1", server.getCore().tempDir(), DATABASE, tableName))); } finally { client.close(); } server.shutdown(); }
Example 2
Source File: HiveServer2CoreTest.java From beeju with Apache License 2.0 | 5 votes |
@Test public void dropPartition() throws Exception { HiveServer2Core server = setupServer(); String tableName = "my_table"; HiveMetaStoreClient client = server.getCore().newClient(); try { Table table = createPartitionedTable(DATABASE, tableName, server); Partition partition = new Partition(); partition.setDbName(DATABASE); partition.setTableName(tableName); partition.setValues(Arrays.asList("1")); partition.setSd(new StorageDescriptor(table.getSd())); partition.getSd().setLocation( String.format("file:%s/%s/%s/partcol=1", server.getCore().tempDir(), DATABASE, tableName)); client.add_partition(partition); try (Connection connection = DriverManager.getConnection(server.getJdbcConnectionUrl()); Statement statement = connection.createStatement()) { String dropPartitionHql = String.format("ALTER TABLE %s.%s DROP PARTITION (partcol=1)", DATABASE, tableName); statement.execute(dropPartitionHql); } List<Partition> partitions = client.listPartitions(DATABASE, tableName, (short) -1); assertThat(partitions.size(), is(0)); } finally { client.close(); } server.shutdown(); }