Github user hyunsik commented on a diff in the pull request:
https://github.com/apache/tajo/pull/618#discussion_r34549680
--- Diff:
tajo-catalog/tajo-catalog-common/src/main/java/org/apache/tajo/catalog/CatalogUtil.java
---
@@ -792,6 +791,69 @@ public static AlterTableDesc setProperty(String
tableName, KeyValueSet params, A
return alterTableDesc;
}
+ /**
+ * Add partition or Drop partition
+ *
+ * @param tableName table name
+ * @param columns partition column names
+ * @param values partition values
+ * @param location partition location
+ * @param alterTableType ADD_PARTITION or DROP_PARTITION
+ * @return
+ */
+ public static AlterTableDesc addOrDropPartition(String tableName,
String[] columns,
+ String[] values, String
location, AlterTableType alterTableType) {
+ final AlterTableDesc alterTableDesc = new AlterTableDesc();
+ alterTableDesc.setTableName(tableName);
+
+ PartitionDesc partitionDesc = new PartitionDesc();
+ Pair<List<PartitionKey>, String> pair =
getPartitionKeyNamePair(columns, values);
+
+ partitionDesc.setPartitionKeys(pair.getFirst());
+ partitionDesc.setPartitionName(pair.getSecond());
+
+ if (alterTableType.equals(AlterTableType.ADD_PARTITION) && location !=
null) {
+ partitionDesc.setPath(location);
+ }
+
+ alterTableDesc.setPartitionDesc(partitionDesc);
+ alterTableDesc.setAlterTableType(alterTableType);
+ return alterTableDesc;
+ }
+
+ /**
+ * Get partition key/value list and partition name
+ *
+ * ex) partition key/value list :
+ * - col1, 2015-07-01
+ * - col2, tajo
+ * partition name : col1=2015-07-01/col2=tajo
+ *
+ * @param columns partition column names
+ * @param values partition values
+ * @return partition key/value list and partition name
+ */
+ public static Pair<List<PartitionKey>, String>
getPartitionKeyNamePair(String[] columns, String[] values) {
+ Pair<List<PartitionKey>, String> pair = null;
+ List<PartitionKey> partitionKeyList = TUtil.newList();
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < columns.length; i++) {
+ PartitionKey partitionKey = new PartitionKey();
--- End diff --
PartitionKey is used as transient intermediate data for PartitionDesc. I
think that PartitionKey is unnecessary. You may use directly PartitionKeyProto
without PartitionKey.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---