use of org.apache.flink.table.api.TableException in project flink by apache.
the class TableEnvironmentImpl method compilePlanAndWrite.
private CompiledPlan compilePlanAndWrite(String filePath, boolean ifNotExists, Operation operation) {
File file = Paths.get(filePath).toFile();
if (file.exists()) {
if (ifNotExists) {
return loadPlan(PlanReference.fromFile(filePath));
}
if (!tableConfig.getConfiguration().get(TableConfigOptions.PLAN_FORCE_RECOMPILE)) {
throw new TableException(String.format("Cannot overwrite the plan file '%s'. " + "Either manually remove the file or, " + "if you're debugging your job, " + "set the option '%s' to true.", filePath, TableConfigOptions.PLAN_FORCE_RECOMPILE.key()));
}
}
CompiledPlan compiledPlan;
if (operation instanceof StatementSetOperation) {
compiledPlan = compilePlan(((StatementSetOperation) operation).getOperations());
} else if (operation instanceof ModifyOperation) {
compiledPlan = compilePlan(Collections.singletonList((ModifyOperation) operation));
} else {
throw new TableException("Unsupported operation to compile: " + operation.getClass() + ". This is a bug, please file an issue.");
}
compiledPlan.writeToFile(file, false);
return compiledPlan;
}
use of org.apache.flink.table.api.TableException in project flink by apache.
the class TableEnvironmentImpl method alterCatalogFunction.
private TableResultInternal alterCatalogFunction(AlterCatalogFunctionOperation alterCatalogFunctionOperation) {
String exMsg = getDDLOpExecuteErrorMsg(alterCatalogFunctionOperation.asSummaryString());
try {
CatalogFunction function = alterCatalogFunctionOperation.getCatalogFunction();
if (alterCatalogFunctionOperation.isTemporary()) {
throw new ValidationException("Alter temporary catalog function is not supported");
} else {
Catalog catalog = getCatalogOrThrowException(alterCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
catalog.alterFunction(alterCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), function, alterCatalogFunctionOperation.isIfExists());
}
return TableResultImpl.TABLE_RESULT_OK;
} catch (ValidationException e) {
throw e;
} catch (FunctionNotExistException e) {
throw new ValidationException(e.getMessage(), e);
} catch (Exception e) {
throw new TableException(exMsg, e);
}
}
use of org.apache.flink.table.api.TableException in project flink by apache.
the class TableEnvironmentImpl method createTemporaryView.
private void createTemporaryView(UnresolvedIdentifier identifier, Table view) {
if (((TableImpl) view).getTableEnvironment() != this) {
throw new TableException("Only table API objects that belong to this TableEnvironment can be registered.");
}
ObjectIdentifier tableIdentifier = catalogManager.qualifyIdentifier(identifier);
QueryOperation queryOperation = qualifyQueryOperation(tableIdentifier, view.getQueryOperation());
CatalogBaseTable tableTable = new QueryOperationCatalogView(queryOperation);
catalogManager.createTemporaryTable(tableTable, tableIdentifier, false);
}
use of org.apache.flink.table.api.TableException in project flink by apache.
the class FunctionCatalog method dropCatalogFunction.
/**
* Drops a catalog function by also considering temporary catalog functions. Returns true if a
* function was dropped.
*/
public boolean dropCatalogFunction(UnresolvedIdentifier unresolvedIdentifier, boolean ignoreIfNotExist) {
final ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
final ObjectIdentifier normalizedIdentifier = FunctionIdentifier.normalizeObjectIdentifier(identifier);
final Catalog catalog = catalogManager.getCatalog(normalizedIdentifier.getCatalogName()).orElseThrow(IllegalStateException::new);
final ObjectPath path = identifier.toObjectPath();
// we force users to deal with temporary catalog functions first
if (tempCatalogFunctions.containsKey(normalizedIdentifier)) {
throw new ValidationException(String.format("Could not drop catalog function. A temporary function '%s' does already exist. " + "Please drop the temporary function first.", identifier.asSummaryString()));
}
if (!catalog.functionExists(path)) {
if (ignoreIfNotExist) {
return false;
}
throw new ValidationException(String.format("Could not drop catalog function. A function '%s' doesn't exist.", identifier.asSummaryString()));
}
try {
catalog.dropFunction(path, ignoreIfNotExist);
} catch (Throwable t) {
throw new TableException(String.format("Could not drop catalog function '%s'.", identifier.asSummaryString()), t);
}
return true;
}
use of org.apache.flink.table.api.TableException in project flink by apache.
the class FunctionCatalog method registerCatalogFunction.
/**
* Registers a catalog function by also considering temporary catalog functions.
*/
public void registerCatalogFunction(UnresolvedIdentifier unresolvedIdentifier, Class<? extends UserDefinedFunction> functionClass, boolean ignoreIfExists) {
final ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
final ObjectIdentifier normalizedIdentifier = FunctionIdentifier.normalizeObjectIdentifier(identifier);
try {
UserDefinedFunctionHelper.validateClass(functionClass);
} catch (Throwable t) {
throw new ValidationException(String.format("Could not register catalog function '%s' due to implementation errors.", identifier.asSummaryString()), t);
}
final Catalog catalog = catalogManager.getCatalog(normalizedIdentifier.getCatalogName()).orElseThrow(IllegalStateException::new);
final ObjectPath path = identifier.toObjectPath();
// we force users to deal with temporary catalog functions first
if (tempCatalogFunctions.containsKey(normalizedIdentifier)) {
if (ignoreIfExists) {
return;
}
throw new ValidationException(String.format("Could not register catalog function. A temporary function '%s' does already exist. " + "Please drop the temporary function first.", identifier.asSummaryString()));
}
if (catalog.functionExists(path)) {
if (ignoreIfExists) {
return;
}
throw new ValidationException(String.format("Could not register catalog function. A function '%s' does already exist.", identifier.asSummaryString()));
}
final CatalogFunction catalogFunction = new CatalogFunctionImpl(functionClass.getName(), FunctionLanguage.JAVA);
try {
catalog.createFunction(path, catalogFunction, ignoreIfExists);
} catch (Throwable t) {
throw new TableException(String.format("Could not register catalog function '%s'.", identifier.asSummaryString()), t);
}
}
Aggregations