@Override public String toString() { return Objects.toStringHelper(this).omitNullValues().add("path", this.path.toString()) .add("db", this.table.getDbName()).add("table", this.table.getTableName()) .add("partition", this.partition.orNull()).toString(); }
private static Map<String, String> getAdditionalMetadata(HiveTable table, Optional<HivePartition> partition, Optional<Exception> error) { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder().put(DB_NAME, table.getDbName()).put(TABLE_NAME, table.getTableName()); if (table.getLocation().isPresent()) { builder.put("Location", table.getLocation().get()); } if (partition.isPresent()) { builder.put("Partition", partition.get().toString()); } if (error.isPresent()) { builder.put(ERROR_MESSAGE, error.get().getMessage()); } return builder.build(); }
private static Map<String, String> getAdditionalMetadata(HiveSpec spec, Optional<Exception> error) { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder().put(DB_NAME, spec.getTable().getDbName()) .put(TABLE_NAME, spec.getTable().getTableName()).put("Path", spec.getPath().toString()); if(spec.getPartition().isPresent()){ builder.put(PARTITIONS, spec.getPartition().get().toString()); } if (error.isPresent()) { builder.put(ERROR_MESSAGE, error.get().getMessage()); } return builder.build(); }
private String getSpecId(HiveSpec spec) { Optional<HivePartition> partition = spec.getPartition(); if (partition.isPresent()) { return String.format("%s.%s@%s", spec.getTable().getDbName(), spec.getTable().getTableName(), Arrays.toString(partition.get().getValues().toArray())); } else { return String.format("%s.%s", spec.getTable().getDbName(), spec.getTable().getTableName()); } }
@Override public String toString() { String table = this.hiveSpec.getTable().getDbName() + "." + this.hiveSpec.getTable().getTableName(); String partitionInfo = this.hiveSpec.getPartition().isPresent() ? " partition " + Arrays.toString(this.hiveSpec.getPartition().get().getValues().toArray()) : ""; String location = this.hiveSpec.getPartition().isPresent() ? this.hiveSpec.getPartition().get().getLocation().get() : this.hiveSpec.getTable().getLocation().get(); return String.format("Register %s%s with location %s in Hive metastore %s.", table, partitionInfo, location, this.metastoreURI.isPresent() ? this.metastoreURI.get() : "default"); } }
@Override public void addOrAlterPartition(HiveTable table, HivePartition partition) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) { addOrAlterPartition(client.get(), HiveMetaStoreUtils.getTable(table), partition); } catch (TException te) { throw new IOException( String.format("Failed to add/alter partition %s.%s@%s", table.getDbName(), table.getTableName(), partition.getValues()), te); } }
private static void examine(HiveSpec spec, String dbName, String tableName) { Assert.assertEquals(spec.getClass(), SimpleHiveSpec.class); Assert.assertEquals(spec.getTable().getDbName(), dbName); Assert.assertEquals(spec.getTable().getTableName(), tableName); } }
@Override public void alterTable(HiveTable table) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) { boolean tableExists; try (Timer.Context context = this.metricContext.timer(TABLE_EXISTS).time()) { tableExists = client.get().tableExists(table.getDbName(), table.getTableName()); } if (!tableExists) { throw new IOException("Table " + table.getTableName() + " in db " + table.getDbName() + " does not exist"); } try (Timer.Context context = this.metricContext.timer(ALTER_TABLE).time()) { client.get().alter_table(table.getDbName(), table.getTableName(), getTableWithCreateTimeNow(HiveMetaStoreUtils.getTable(table))); } HiveMetaStoreEventHelper.submitSuccessfulTableAlter(eventSubmitter, table); } catch (TException e) { HiveMetaStoreEventHelper.submitFailedTableAlter(eventSubmitter, table, e); throw new IOException("Unable to alter table " + table.getTableName() + " in db " + table.getDbName(), e); } }
@Override public void alterPartition(HiveTable table, HivePartition partition) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) { try (Timer.Context context = this.metricContext.timer(ALTER_PARTITION).time()) { client.get().alter_partition(table.getDbName(), table.getTableName(), getPartitionWithCreateTimeNow(HiveMetaStoreUtils.getPartition(partition))); } HiveMetaStoreEventHelper.submitSuccessfulPartitionAlter(eventSubmitter, table, partition); } catch (TException e) { HiveMetaStoreEventHelper.submitFailedPartitionAlter(eventSubmitter, table, partition, e); throw new IOException(String.format("Unable to alter partition %s in table %s in db %s", partition.getValues(), table.getTableName(), table.getDbName()), e); } }
@Override public boolean createTableIfNotExists(HiveTable table) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient(); AutoCloseableLock lock = this.locks.getTableLock(table.getDbName(), table.getTableName())) { return createTableIfNotExists(client.get(), HiveMetaStoreUtils.getTable(table), table); } }
@Override public boolean addPartitionIfNotExists(HiveTable table, HivePartition partition) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient(); AutoCloseableLock lock = this.locks.getTableLock(table.getDbName(), table.getTableName())) { try { try (Timer.Context context = this.metricContext.timer(GET_HIVE_PARTITION).time()) { client.get().getPartition(table.getDbName(), table.getTableName(), partition.getValues()); } return false; } catch (NoSuchObjectException e) { try (Timer.Context context = this.metricContext.timer(ADD_PARTITION_TIMER).time()) { client.get().add_partition(getPartitionWithCreateTimeNow(HiveMetaStoreUtils.getPartition(partition))); } HiveMetaStoreEventHelper.submitSuccessfulPartitionAdd(this.eventSubmitter, table, partition); return true; } } catch (TException e) { HiveMetaStoreEventHelper.submitFailedPartitionAdd(this.eventSubmitter, table, partition, e); throw new IOException(String.format("Unable to add partition %s in table %s in db %s", partition.getValues(), table.getTableName(), table.getDbName()), e); } }
Table table = new Table(); table.setDbName(hiveTable.getDbName()); table.setTableName(hiveTable.getTableName()); table.setParameters(getParameters(props)); if (hiveTable.getCreateTime().isPresent()) {
@Override public String toString() { return Objects.toStringHelper(this).omitNullValues().add("path", this.path.toString()) .add("db", this.table.getDbName()).add("table", this.table.getTableName()) .add("partition", this.partition.orNull()).toString(); }
private static Map<String, String> getAdditionalMetadata(HiveTable table, Optional<HivePartition> partition, Optional<Exception> error) { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder().put(DB_NAME, table.getDbName()).put(TABLE_NAME, table.getTableName()); if (table.getLocation().isPresent()) { builder.put("Location", table.getLocation().get()); } if (partition.isPresent()) { builder.put("Partition", partition.get().toString()); } if (error.isPresent()) { builder.put(ERROR_MESSAGE, error.get().getMessage()); } return builder.build(); }
private static Map<String, String> getAdditionalMetadata(HiveSpec spec, Optional<Exception> error) { ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String> builder().put(DB_NAME, spec.getTable().getDbName()) .put(TABLE_NAME, spec.getTable().getTableName()).put("Path", spec.getPath().toString()); if(spec.getPartition().isPresent()){ builder.put(PARTITIONS, spec.getPartition().get().toString()); } if (error.isPresent()) { builder.put(ERROR_MESSAGE, error.get().getMessage()); } return builder.build(); }
private String getSpecId(HiveSpec spec) { Optional<HivePartition> partition = spec.getPartition(); if (partition.isPresent()) { return String.format("%s.%s@%s", spec.getTable().getDbName(), spec.getTable().getTableName(), Arrays.toString(partition.get().getValues().toArray())); } else { return String.format("%s.%s", spec.getTable().getDbName(), spec.getTable().getTableName()); } }
@Override public String toString() { String table = this.hiveSpec.getTable().getDbName() + "." + this.hiveSpec.getTable().getTableName(); String partitionInfo = this.hiveSpec.getPartition().isPresent() ? " partition " + Arrays.toString(this.hiveSpec.getPartition().get().getValues().toArray()) : ""; String location = this.hiveSpec.getPartition().isPresent() ? this.hiveSpec.getPartition().get().getLocation().get() : this.hiveSpec.getTable().getLocation().get(); return String.format("Register %s%s with location %s in Hive metastore %s.", table, partitionInfo, location, this.metastoreURI.isPresent() ? this.metastoreURI.get() : "default"); } }
@Override public void addOrAlterPartition(HiveTable table, HivePartition partition) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) { addOrAlterPartition(client.get(), HiveMetaStoreUtils.getTable(table), partition); } catch (TException te) { throw new IOException( String.format("Failed to add/alter partition %s.%s@%s", table.getDbName(), table.getTableName(), partition.getValues()), te); } }
@Override public void alterPartition(HiveTable table, HivePartition partition) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient()) { try (Timer.Context context = this.metricContext.timer(ALTER_PARTITION).time()) { client.get().alter_partition(table.getDbName(), table.getTableName(), getPartitionWithCreateTimeNow(HiveMetaStoreUtils.getPartition(partition))); } HiveMetaStoreEventHelper.submitSuccessfulPartitionAlter(eventSubmitter, table, partition); } catch (TException e) { HiveMetaStoreEventHelper.submitFailedPartitionAlter(eventSubmitter, table, partition, e); throw new IOException(String.format("Unable to alter partition %s in table %s in db %s", partition.getValues(), table.getTableName(), table.getDbName()), e); } }
@Override public boolean createTableIfNotExists(HiveTable table) throws IOException { try (AutoReturnableObject<IMetaStoreClient> client = this.clientPool.getClient(); AutoCloseableLock lock = this.locks.getTableLock(table.getDbName(), table.getTableName())) { return createTableIfNotExists(client.get(), HiveMetaStoreUtils.getTable(table), table); } }