1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| sqlUpdate ->parser.parse()->operations ->CreateTableOperation ->createTable()
@Override public void sqlUpdate(String stmt) { List<Operation> operations = parser.parse(stmt);
if (operations.size() != 1) { throw new TableException(UNSUPPORTED_QUERY_IN_SQL_UPDATE_MSG); }
Operation operation = operations.get(0);
if (operation instanceof ModifyOperation) { List<ModifyOperation> modifyOperations = Collections.singletonList((ModifyOperation) operation); if (isEagerOperationTranslation()) { translate(modifyOperations); } else { buffer(modifyOperations); } } else if (operation instanceof CreateTableOperation) { CreateTableOperation createTableOperation = (CreateTableOperation) operation; catalogManager.createTable( createTableOperation.getCatalogTable(), createTableOperation.getTableIdentifier(), createTableOperation.isIgnoreIfExists()); } else if (operation instanceof CreateDatabaseOperation) { CreateDatabaseOperation createDatabaseOperation = (CreateDatabaseOperation) operation; Catalog catalog = getCatalogOrThrowException(createDatabaseOperation.getCatalogName()); String exMsg = getDDLOpExecuteErrorMsg(createDatabaseOperation.asSummaryString()); try { catalog.createDatabase( createDatabaseOperation.getDatabaseName(), createDatabaseOperation.getCatalogDatabase(), createDatabaseOperation.isIgnoreIfExists()); } catch (DatabaseAlreadyExistException e) { throw new ValidationException(exMsg, e); } catch (Exception e) { throw new TableException(exMsg, e); } } else if (operation instanceof DropTableOperation) { DropTableOperation dropTableOperation = (DropTableOperation) operation; catalogManager.dropTable( dropTableOperation.getTableIdentifier(), dropTableOperation.isIfExists()); } else if (operation instanceof AlterTableOperation) { AlterTableOperation alterTableOperation = (AlterTableOperation) operation; Catalog catalog = getCatalogOrThrowException(alterTableOperation.getTableIdentifier().getCatalogName()); String exMsg = getDDLOpExecuteErrorMsg(alterTableOperation.asSummaryString()); try { if (alterTableOperation instanceof AlterTableRenameOperation) { AlterTableRenameOperation alterTableRenameOp = (AlterTableRenameOperation) operation; catalog.renameTable( alterTableRenameOp.getTableIdentifier().toObjectPath(), alterTableRenameOp.getNewTableIdentifier().getObjectName(), false); } else if (alterTableOperation instanceof AlterTablePropertiesOperation){ AlterTablePropertiesOperation alterTablePropertiesOp = (AlterTablePropertiesOperation) operation; catalog.alterTable( alterTablePropertiesOp.getTableIdentifier().toObjectPath(), alterTablePropertiesOp.getCatalogTable(), false); } } catch (TableAlreadyExistException | TableNotExistException e) { throw new ValidationException(exMsg, e); } catch (Exception e) { throw new TableException(exMsg, e); } } else if (operation instanceof DropDatabaseOperation) { DropDatabaseOperation dropDatabaseOperation = (DropDatabaseOperation) operation; Catalog catalog = getCatalogOrThrowException(dropDatabaseOperation.getCatalogName()); String exMsg = getDDLOpExecuteErrorMsg(dropDatabaseOperation.asSummaryString()); try { catalog.dropDatabase( dropDatabaseOperation.getDatabaseName(), dropDatabaseOperation.isIfExists(), dropDatabaseOperation.isCascade()); } catch (DatabaseNotExistException | DatabaseNotEmptyException e) { throw new ValidationException(exMsg, e); } catch (Exception e) { throw new TableException(exMsg, e); } } else if (operation instanceof AlterDatabaseOperation) { AlterDatabaseOperation alterDatabaseOperation = (AlterDatabaseOperation) operation; Catalog catalog = getCatalogOrThrowException(alterDatabaseOperation.getCatalogName()); String exMsg = getDDLOpExecuteErrorMsg(alterDatabaseOperation.asSummaryString()); try { catalog.alterDatabase( alterDatabaseOperation.getDatabaseName(), alterDatabaseOperation.getCatalogDatabase(), false); } catch (DatabaseNotExistException e) { throw new ValidationException(exMsg, e); } catch (Exception e) { throw new TableException(exMsg, e); } } else if (operation instanceof CreateFunctionOperation) { CreateFunctionOperation createFunctionOperation = (CreateFunctionOperation) operation; createCatalogFunction(createFunctionOperation); } else if (operation instanceof CreateTempSystemFunctionOperation) { CreateTempSystemFunctionOperation createtempSystemFunctionOperation = (CreateTempSystemFunctionOperation) operation; createSystemFunction(createtempSystemFunctionOperation); } else if (operation instanceof AlterFunctionOperation) { AlterFunctionOperation alterFunctionOperation = (AlterFunctionOperation) operation; alterCatalogFunction(alterFunctionOperation); } else if (operation instanceof DropFunctionOperation) { DropFunctionOperation dropFunctionOperation = (DropFunctionOperation) operation; dropCatalogFunction(dropFunctionOperation); } else if (operation instanceof DropTempSystemFunctionOperation) { DropTempSystemFunctionOperation dropTempSystemFunctionOperation = (DropTempSystemFunctionOperation) operation; dropSystemFunction(dropTempSystemFunctionOperation); } else if (operation instanceof UseCatalogOperation) { UseCatalogOperation useCatalogOperation = (UseCatalogOperation) operation; catalogManager.setCurrentCatalog(useCatalogOperation.getCatalogName()); } else if (operation instanceof UseDatabaseOperation) { UseDatabaseOperation useDatabaseOperation = (UseDatabaseOperation) operation; catalogManager.setCurrentCatalog(useDatabaseOperation.getCatalogName()); catalogManager.setCurrentDatabase(useDatabaseOperation.getDatabaseName()); } else { throw new TableException(UNSUPPORTED_QUERY_IN_SQL_UPDATE_MSG); } }
public void createTable(CatalogBaseTable table, ObjectIdentifier objectIdentifier, boolean ignoreIfExists) { execute( (catalog, path) -> catalog.createTable(path, table, ignoreIfExists), objectIdentifier, false, "CreateTable"); }
|