final String tableName = alterTable.getTableName(); if (alterTable.getAlterTableOpType() == AlterTableOpType.RENAME_TABLE || alterTable.getAlterTableOpType() == AlterTableOpType.ADD_PARTITION || alterTable.getAlterTableOpType() == AlterTableOpType.DROP_PARTITION) { desc = catalog.getTableDesc(databaseName, simpleTableName); switch (alterTable.getAlterTableOpType()) { case RENAME_TABLE: if (!catalog.existsTable(databaseName, simpleTableName)) { throw new UndefinedTableException(alterTable.getTableName()); if (catalog.existsTable(databaseName, alterTable.getNewTableName())) { throw new DuplicateTableException(alterTable.getNewTableName()); databaseName, simpleTableName); newPath = StorageUtil.concatPath(context.getConf().getVar(TajoConf.ConfVars.WAREHOUSE_DIR), databaseName, alterTable.getNewTableName()); FileSystem fs = oldPath.getFileSystem(context.getConf()); catalog.alterTable(CatalogUtil.renameTable(qualifiedName, alterTable.getNewTableName(), AlterTableType.RENAME_TABLE, newPath)); break; case RENAME_COLUMN: if (ensureColumnExistance(qualifiedName, alterTable.getNewColumnName())) { throw new DuplicateColumnException(alterTable.getNewColumnName()); catalog.alterTable(CatalogUtil.renameColumn(qualifiedName, alterTable.getColumnName(), alterTable.getNewColumnName(), AlterTableType.RENAME_COLUMN));
AlterTableNode node, Stack<LogicalNode> stack) { PlanProto.AlterTableNode.Builder alterTableBuilder = PlanProto.AlterTableNode.newBuilder(); alterTableBuilder.setTableName(node.getTableName()); PlanProto.AlterTableNode.AlterPartition.Builder partitionBuilder = null; switch (node.getAlterTableOpType()) { case RENAME_TABLE: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.RENAME_TABLE); alterTableBuilder.setRenameTable(RenameTable.newBuilder().setNewName(node.getNewTableName())); break; case ADD_COLUMN: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.ADD_COLUMN); alterTableBuilder.setAddColumn(AddColumn.newBuilder().setAddColumn(node.getAddNewColumn().getProto())); break; case RENAME_COLUMN: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.RENAME_COLUMN); alterTableBuilder.setRenameColumn(RenameColumn.newBuilder() .setOldName(node.getColumnName()) .setNewName(node.getNewColumnName())); break; case SET_PROPERTY: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.SET_PROPERTY); alterTableBuilder.setProperties(node.getProperties().getProto()); break; case UNSET_PROPERTY: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.UNSET_PROPERTY); alterTableBuilder.setUnsetPropertyKeys(ProtoUtil.convertStrings(Arrays.asList(node.getUnsetPropertyKeys()))); break; case ADD_PARTITION:
assertEquals(alterTableNode.getAlterTableOpType(), AlterTableOpType.ADD_PARTITION); assertEquals(alterTableNode.getPartitionColumns().length, 2); assertEquals(alterTableNode.getPartitionValues().length, 2); assertEquals(alterTableNode.getPartitionColumns()[0], "col1"); assertEquals(alterTableNode.getPartitionColumns()[1], "col2"); assertEquals(alterTableNode.getPartitionValues()[0], "1"); assertEquals(alterTableNode.getPartitionValues()[1], "2"); assertEquals(alterTableNode.getLocation(), "hdfs://xxx.com/warehouse/partitioned_table/col1=1/col2=2"); assertEquals(alterTableNode.getAlterTableOpType(), AlterTableOpType.DROP_PARTITION); assertEquals(alterTableNode.getPartitionColumns().length, 3); assertEquals(alterTableNode.getPartitionValues().length, 3); assertEquals(alterTableNode.getPartitionColumns()[0], "col1"); assertEquals(alterTableNode.getPartitionColumns()[1], "col2"); assertEquals(alterTableNode.getPartitionColumns()[2], "col3"); assertEquals(alterTableNode.getPartitionValues()[0], "2015"); assertEquals(alterTableNode.getPartitionValues()[1], "01"); assertEquals(alterTableNode.getPartitionValues()[2], "11");
@Test public final void testAlterTableRepairPartiton() throws TajoException { QueryContext qc = createQueryContext(); String sql = "ALTER TABLE table1 REPAIR PARTITION"; Expr expr = sqlAnalyzer.parse(sql); LogicalPlan rootNode = planner.createPlan(qc, expr); LogicalNode plan = rootNode.getRootBlock().getRoot(); assertEquals(NodeType.ROOT, plan.getType()); LogicalRootNode root = (LogicalRootNode) plan; assertEquals(NodeType.ALTER_TABLE, root.getChild().getType()); AlterTableNode msckNode = root.getChild(); assertEquals(msckNode.getAlterTableOpType(), AlterTableOpType.REPAIR_PARTITION); assertEquals(msckNode.getTableName(), "table1"); }
final AlterTableNode alterTable) throws IOException, TajoException { final CatalogService catalog = context.getCatalog(); final String tableName = alterTable.getTableName(); throw new UndefinedTableException(alterTable.getTableName());
AlterTableNode node, Stack<LogicalNode> stack) { PlanProto.AlterTableNode.Builder alterTableBuilder = PlanProto.AlterTableNode.newBuilder(); alterTableBuilder.setTableName(node.getTableName()); PlanProto.AlterTableNode.AlterPartition.Builder partitionBuilder = null; switch (node.getAlterTableOpType()) { case RENAME_TABLE: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.RENAME_TABLE); alterTableBuilder.setRenameTable(RenameTable.newBuilder().setNewName(node.getNewTableName())); break; case ADD_COLUMN: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.ADD_COLUMN); alterTableBuilder.setAddColumn(AddColumn.newBuilder().setAddColumn(node.getAddNewColumn().getProto())); break; case RENAME_COLUMN: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.RENAME_COLUMN); alterTableBuilder.setRenameColumn(RenameColumn.newBuilder() .setOldName(node.getColumnName()) .setNewName(node.getNewColumnName())); break; case SET_PROPERTY: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.SET_PROPERTY); alterTableBuilder.setProperties(node.getProperties().getProto()); break; case ADD_PARTITION: alterTableBuilder.setSetType(PlanProto.AlterTableNode.Type.ADD_PARTITION); partitionBuilder = PlanProto.AlterTableNode.AlterPartition.newBuilder(); for (String columnName : node.getPartitionColumns()) { partitionBuilder.addColumnNames(columnName);
final AlterTableNode alterTable) throws IOException, TajoException { final CatalogService catalog = context.getCatalog(); final String tableName = alterTable.getTableName(); throw new UndefinedTableException(alterTable.getTableName());
final String tableName = alterTable.getTableName(); if (alterTable.getAlterTableOpType() == AlterTableOpType.RENAME_TABLE || alterTable.getAlterTableOpType() == AlterTableOpType.ADD_PARTITION || alterTable.getAlterTableOpType() == AlterTableOpType.DROP_PARTITION) { desc = catalog.getTableDesc(databaseName, simpleTableName); switch (alterTable.getAlterTableOpType()) { case RENAME_TABLE: if (!catalog.existsTable(databaseName, simpleTableName)) { throw new UndefinedTableException(alterTable.getTableName()); if (catalog.existsTable(databaseName, alterTable.getNewTableName())) { throw new DuplicateTableException(alterTable.getNewTableName()); databaseName, simpleTableName); newPath = StorageUtil.concatPath(context.getConf().getVar(TajoConf.ConfVars.WAREHOUSE_DIR), databaseName, alterTable.getNewTableName()); FileSystem fs = oldPath.getFileSystem(context.getConf()); catalog.alterTable(CatalogUtil.renameTable(qualifiedName, alterTable.getNewTableName(), newPath)); break; case RENAME_COLUMN: if (ensureColumnExistance(qualifiedName, alterTable.getNewColumnName())) { throw new DuplicateColumnException(alterTable.getNewColumnName()); catalog.alterTable(CatalogUtil.renameColumn(qualifiedName, alterTable.getColumnName(), alterTable.getNewColumnName()));