Search in sources :

Example 6 with UnresolvedIdentifier

use of org.apache.flink.table.catalog.UnresolvedIdentifier in project flink by apache.

the class TableEnvironmentImpl method registerTable.

@Override
public void registerTable(String name, Table table) {
    UnresolvedIdentifier identifier = UnresolvedIdentifier.of(name);
    createTemporaryView(identifier, table);
}
Also used : UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier)

Example 7 with UnresolvedIdentifier

use of org.apache.flink.table.catalog.UnresolvedIdentifier in project flink by apache.

the class SqlToOperationConverter method convertCreateFunction.

/**
 * Convert CREATE FUNCTION statement.
 */
private Operation convertCreateFunction(SqlCreateFunction sqlCreateFunction) {
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlCreateFunction.getFunctionIdentifier());
    if (sqlCreateFunction.isSystemFunction()) {
        return new CreateTempSystemFunctionOperation(unresolvedIdentifier.getObjectName(), sqlCreateFunction.getFunctionClassName().getValueAs(String.class), sqlCreateFunction.isIfNotExists(), parseLanguage(sqlCreateFunction.getFunctionLanguage()));
    } else {
        FunctionLanguage language = parseLanguage(sqlCreateFunction.getFunctionLanguage());
        CatalogFunction catalogFunction = new CatalogFunctionImpl(sqlCreateFunction.getFunctionClassName().getValueAs(String.class), language);
        ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
        return new CreateCatalogFunctionOperation(identifier, catalogFunction, sqlCreateFunction.isIfNotExists(), sqlCreateFunction.isTemporary());
    }
}
Also used : CreateCatalogFunctionOperation(org.apache.flink.table.operations.ddl.CreateCatalogFunctionOperation) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) FunctionLanguage(org.apache.flink.table.catalog.FunctionLanguage) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) CreateTempSystemFunctionOperation(org.apache.flink.table.operations.ddl.CreateTempSystemFunctionOperation) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 8 with UnresolvedIdentifier

use of org.apache.flink.table.catalog.UnresolvedIdentifier in project flink by apache.

the class SqlToOperationConverter method convertAlterFunction.

/**
 * Convert ALTER FUNCTION statement.
 */
private Operation convertAlterFunction(SqlAlterFunction sqlAlterFunction) {
    if (sqlAlterFunction.isSystemFunction()) {
        throw new ValidationException("Alter temporary system function is not supported");
    }
    FunctionLanguage language = parseLanguage(sqlAlterFunction.getFunctionLanguage());
    CatalogFunction catalogFunction = new CatalogFunctionImpl(sqlAlterFunction.getFunctionClassName().getValueAs(String.class), language);
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlAlterFunction.getFunctionIdentifier());
    ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    return new AlterCatalogFunctionOperation(identifier, catalogFunction, sqlAlterFunction.isIfExists(), sqlAlterFunction.isTemporary());
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) AlterCatalogFunctionOperation(org.apache.flink.table.operations.ddl.AlterCatalogFunctionOperation) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) FunctionLanguage(org.apache.flink.table.catalog.FunctionLanguage) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 9 with UnresolvedIdentifier

use of org.apache.flink.table.catalog.UnresolvedIdentifier in project flink by apache.

the class SqlToOperationConverter method convertAlterView.

/**
 * convert ALTER VIEW statement.
 */
private Operation convertAlterView(SqlAlterView alterView) {
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(alterView.fullViewName());
    ObjectIdentifier viewIdentifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    Optional<ContextResolvedTable> optionalCatalogTable = catalogManager.getTable(viewIdentifier);
    if (!optionalCatalogTable.isPresent() || optionalCatalogTable.get().isTemporary()) {
        throw new ValidationException(String.format("View %s doesn't exist or is a temporary view.", viewIdentifier.toString()));
    }
    CatalogBaseTable baseTable = optionalCatalogTable.get().getTable();
    if (baseTable instanceof CatalogTable) {
        throw new ValidationException("ALTER VIEW for a table is not allowed");
    }
    if (alterView instanceof SqlAlterViewRename) {
        UnresolvedIdentifier newUnresolvedIdentifier = UnresolvedIdentifier.of(((SqlAlterViewRename) alterView).fullNewViewName());
        ObjectIdentifier newTableIdentifier = catalogManager.qualifyIdentifier(newUnresolvedIdentifier);
        return new AlterViewRenameOperation(viewIdentifier, newTableIdentifier);
    } else if (alterView instanceof SqlAlterViewProperties) {
        SqlAlterViewProperties alterViewProperties = (SqlAlterViewProperties) alterView;
        CatalogView oldView = (CatalogView) baseTable;
        Map<String, String> newProperties = new HashMap<>(oldView.getOptions());
        newProperties.putAll(OperationConverterUtils.extractProperties(alterViewProperties.getPropertyList()));
        CatalogView newView = new CatalogViewImpl(oldView.getOriginalQuery(), oldView.getExpandedQuery(), oldView.getSchema(), newProperties, oldView.getComment());
        return new AlterViewPropertiesOperation(viewIdentifier, newView);
    } else if (alterView instanceof SqlAlterViewAs) {
        SqlAlterViewAs alterViewAs = (SqlAlterViewAs) alterView;
        final SqlNode newQuery = alterViewAs.getNewQuery();
        CatalogView oldView = (CatalogView) baseTable;
        CatalogView newView = convertViewQuery(newQuery, Collections.emptyList(), oldView.getOptions(), oldView.getComment());
        return new AlterViewAsOperation(viewIdentifier, newView);
    } else {
        throw new ValidationException(String.format("[%s] needs to implement", alterView.toSqlString(CalciteSqlDialect.DEFAULT)));
    }
}
Also used : AlterViewPropertiesOperation(org.apache.flink.table.operations.ddl.AlterViewPropertiesOperation) AlterViewAsOperation(org.apache.flink.table.operations.ddl.AlterViewAsOperation) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) ValidationException(org.apache.flink.table.api.ValidationException) CatalogViewImpl(org.apache.flink.table.catalog.CatalogViewImpl) SqlAlterViewRename(org.apache.flink.sql.parser.ddl.SqlAlterViewRename) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) CatalogTable(org.apache.flink.table.catalog.CatalogTable) ResolvedCatalogTable(org.apache.flink.table.catalog.ResolvedCatalogTable) AlterViewRenameOperation(org.apache.flink.table.operations.ddl.AlterViewRenameOperation) SqlAlterViewAs(org.apache.flink.sql.parser.ddl.SqlAlterViewAs) SqlAlterViewProperties(org.apache.flink.sql.parser.ddl.SqlAlterViewProperties) ContextResolvedTable(org.apache.flink.table.catalog.ContextResolvedTable) CatalogView(org.apache.flink.table.catalog.CatalogView) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier) SqlNode(org.apache.calcite.sql.SqlNode)

Example 10 with UnresolvedIdentifier

use of org.apache.flink.table.catalog.UnresolvedIdentifier in project flink by apache.

the class SqlToOperationConverter method convertShowCreateTable.

/**
 * Convert SHOW CREATE TABLE statement.
 */
private Operation convertShowCreateTable(SqlShowCreateTable sqlShowCreateTable) {
    UnresolvedIdentifier unresolvedIdentifier = UnresolvedIdentifier.of(sqlShowCreateTable.getFullTableName());
    ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    return new ShowCreateTableOperation(identifier);
}
Also used : UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) ShowCreateTableOperation(org.apache.flink.table.operations.ShowCreateTableOperation) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Aggregations

UnresolvedIdentifier (org.apache.flink.table.catalog.UnresolvedIdentifier)25 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)20 ValidationException (org.apache.flink.table.api.ValidationException)9 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)7 CatalogTable (org.apache.flink.table.catalog.CatalogTable)5 LinkedHashMap (java.util.LinkedHashMap)4 ResolvedCatalogTable (org.apache.flink.table.catalog.ResolvedCatalogTable)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)3 CatalogFunction (org.apache.flink.table.catalog.CatalogFunction)3 CatalogFunctionImpl (org.apache.flink.table.catalog.CatalogFunctionImpl)3 FunctionLanguage (org.apache.flink.table.catalog.FunctionLanguage)3 Optional (java.util.Optional)2 RelHint (org.apache.calcite.rel.hint.RelHint)2 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)2 SqlNode (org.apache.calcite.sql.SqlNode)2 SqlAlterViewAs (org.apache.flink.sql.parser.ddl.SqlAlterViewAs)2