/** * Gets the partition columns of the table. * * @return the partition columns */ public List<HCatFieldSchema> getPartColumns() { return hcatTable.getPartCols(); }
/** * Gets the partition cols. * * @return the partition cols */ @Deprecated // @deprecated in favour of {@link HCatTable.#getPartCols()}. To be removed in Hive 0.16. public List<HCatFieldSchema> getPartitionCols() { return this.hcatTable.getPartCols(); }
/** * Getter for partition-spec map. */ public LinkedHashMap<String, String> getPartitionKeyValMap() { LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(hcatTable.getPartCols().size()); for (int i=0; i<hcatTable.getPartCols().size(); ++i) { map.put(hcatTable.getPartCols().get(i).getName(), values.get(i)); } return map; }
public HCatPartition(HCatPartition rhs, Map<String, String> partitionKeyValues, String location) throws HCatException { this.hcatTable = rhs.hcatTable; this.tableName = rhs.tableName; this.dbName = rhs.dbName; this.sd = new StorageDescriptor(rhs.sd); this.sd.setLocation(location); this.columns = getColumns(this.sd); this.createTime = (int) (System.currentTimeMillis() / 1000); this.lastAccessTime = -1; this.values = new ArrayList<String>(hcatTable.getPartCols().size()); for (HCatFieldSchema partField : hcatTable.getPartCols()) { if (!partitionKeyValues.containsKey(partField.getName())) { throw new HCatException("Missing value for partition-key \'" + partField.getName() + "\' in table: " + hcatTable.getDbName() + "." + hcatTable.getTableName()); } else { values.add(partitionKeyValues.get(partField.getName())); } } }
/** * Setter for partition key-values. */ public HCatPartition setPartitionKeyValues(Map<String, String> partitionKeyValues) throws HCatException { for (HCatFieldSchema partField : hcatTable.getPartCols()) { if (!partitionKeyValues.containsKey(partField.getName())) { throw new HCatException("Missing value for partition-key \'" + partField.getName() + "\' in table: " + hcatTable.getDbName() + "." + hcatTable.getTableName()); } else { values.add(partitionKeyValues.get(partField.getName())); // Keep partKeyValMap in synch as well. } } return this; }
public HCatPartition(HCatTable hcatTable, Map<String, String> partitionKeyValues, String location) throws HCatException { this.hcatTable = hcatTable; this.tableName = hcatTable.getTableName(); this.dbName = hcatTable.getDbName(); this.sd = new StorageDescriptor(hcatTable.getSd()); this.sd.setLocation(location); this.columns = getColumns(this.sd); this.createTime = (int)(System.currentTimeMillis()/1000); this.lastAccessTime = -1; this.values = new ArrayList<String>(hcatTable.getPartCols().size()); for (HCatFieldSchema partField : hcatTable.getPartCols()) { if (!partitionKeyValues.containsKey(partField.getName())) { throw new HCatException("Missing value for partition-key \'" + partField.getName() + "\' in table: " + hcatTable.getDbName() + "." + hcatTable.getTableName()); } else { values.add(partitionKeyValues.get(partField.getName())); } } }
try { HCatTable hcatTable = getTable(dbName, tableName); List<HCatFieldSchema> partitionColumns = hcatTable.getPartCols(); if (partitionColumns.size() != partitionSpec.size()) { throw new HCatException("Partition-spec doesn't have the right number of partition keys.");
Partition toHivePartition() throws HCatException { Partition hivePtn = new Partition(); hivePtn.setDbName(dbName); hivePtn.setTableName(tableName); hivePtn.setValues(values); hivePtn.setParameters(parameters); if (sd.getLocation() == null) { LOG.warn("Partition location is not set! Attempting to construct default partition location."); try { String partName = Warehouse.makePartName(HCatSchemaUtils.getFieldSchemas(hcatTable.getPartCols()), values); sd.setLocation(new Path(hcatTable.getSd().getLocation(), partName).toString()); } catch(MetaException exception) { throw new HCatException("Could not construct default partition-path for " + hcatTable.getDbName() + "." + hcatTable.getTableName() + "[" + values + "]"); } } hivePtn.setSd(sd); hivePtn.setCreateTime((int) (System.currentTimeMillis() / 1000)); hivePtn.setLastAccessTimeIsSet(false); return hivePtn; }
HCatPartition(HCatTable hcatTable, Partition partition) throws HCatException { this.hcatTable = hcatTable; this.tableName = partition.getTableName(); this.dbName = partition.getDbName(); this.createTime = partition.getCreateTime(); this.lastAccessTime = partition.getLastAccessTime(); this.parameters = partition.getParameters(); this.values = partition.getValues(); if (hcatTable != null && partition.getValuesSize() != hcatTable.getPartCols().size()) { throw new HCatException("Mismatched number of partition columns between table:" + hcatTable.getDbName() + "." + hcatTable.getTableName() + " and partition " + partition.getValues()); } this.sd = partition.getSd(); this.columns = getColumns(this.sd); }
@Test public void testPartitionSchema() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); final String dbName = "myDb"; final String tableName = "myTable"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); List<HCatFieldSchema> columnSchema = Arrays.asList(new HCatFieldSchema("foo", Type.INT, ""), new HCatFieldSchema("bar", Type.STRING, "")); List<HCatFieldSchema> partitionSchema = Arrays.asList(new HCatFieldSchema("dt", Type.STRING, ""), new HCatFieldSchema("grid", Type.STRING, "")); client.createTable(HCatCreateTableDesc.create(dbName, tableName, columnSchema).partCols(partitionSchema).build()); HCatTable table = client.getTable(dbName, tableName); List<HCatFieldSchema> partitionColumns = table.getPartCols(); assertArrayEquals("Didn't get expected partition-schema back from the HCatTable.", partitionSchema.toArray(), partitionColumns.toArray()); client.dropDatabase(dbName, false, HCatClient.DropDBMode.CASCADE); } catch (Exception unexpected) { LOG.error("Unexpected exception!", unexpected); assertTrue("Unexpected exception! " + unexpected.getMessage(), false); } }
/** * Gets the partition columns of the table. * * @return the partition columns */ public List<HCatFieldSchema> getPartColumns() { return hcatTable.getPartCols(); }
/** * Gets the partition columns of the table. * * @return the partition columns */ public List<HCatFieldSchema> getPartColumns() { return hcatTable.getPartCols(); }
/** * Gets the partition columns of the table. * * @return the partition columns */ public List<HCatFieldSchema> getPartColumns() { return hcatTable.getPartCols(); }
/** * Gets the partition cols. * * @return the partition cols */ @Deprecated // @deprecated in favour of {@link HCatTable.#getPartCols()}. To be removed in Hive 0.16. public List<HCatFieldSchema> getPartitionCols() { return this.hcatTable.getPartCols(); }
/** * Gets the partition cols. * * @return the partition cols */ @Deprecated // @deprecated in favour of {@link HCatTable.#getPartCols()}. To be removed in Hive 0.16. public List<HCatFieldSchema> getPartitionCols() { return this.hcatTable.getPartCols(); }
/** * Gets the partition cols. * * @return the partition cols */ @Deprecated // @deprecated in favour of {@link HCatTable.#getPartCols()}. To be removed in Hive 0.16. public List<HCatFieldSchema> getPartitionCols() { return this.hcatTable.getPartCols(); }
/** * Getter for partition-spec map. */ public LinkedHashMap<String, String> getPartitionKeyValMap() { LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(hcatTable.getPartCols().size()); for (int i=0; i<hcatTable.getPartCols().size(); ++i) { map.put(hcatTable.getPartCols().get(i).getName(), values.get(i)); } return map; }
/** * Getter for partition-spec map. */ public LinkedHashMap<String, String> getPartitionKeyValMap() { LinkedHashMap<String, String> map = new LinkedHashMap<String, String>(hcatTable.getPartCols().size()); for (int i=0; i<hcatTable.getPartCols().size(); ++i) { map.put(hcatTable.getPartCols().get(i).getName(), values.get(i)); } return map; }
TableDataBuilder(HCatTable table) { schema = new HCatSchema(ImmutableList .<HCatFieldSchema> builder() .addAll(table.getCols()) .addAll(table.getPartCols()) .build()); partitionColumns = table.getPartCols(); withAllColumns(); }
TableDataBuilder(HCatTable table) { schema = new HCatSchema(ImmutableList .<HCatFieldSchema> builder() .addAll(table.getCols()) .addAll(table.getPartCols()) .build()); partitionColumns = table.getPartCols(); withAllColumns(); }