Search in sources :

Example 6 with CatalogFunctionImpl

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

the class HiveParserDDLSemanticAnalyzer method convertCreateFunction.

private Operation convertCreateFunction(HiveParserASTNode ast) {
    // ^(TOK_CREATEFUNCTION identifier StringLiteral ({isTempFunction}? => TOK_TEMPORARY))
    String functionName = ast.getChild(0).getText().toLowerCase();
    boolean isTemporaryFunction = (ast.getFirstChildWithType(HiveASTParser.TOK_TEMPORARY) != null);
    String className = HiveParserBaseSemanticAnalyzer.unescapeSQLString(ast.getChild(1).getText());
    // Temp functions are not allowed to have qualified names.
    if (isTemporaryFunction && FunctionUtils.isQualifiedFunctionName(functionName)) {
        // belong to a catalog/db
        throw new ValidationException("Temporary function cannot be created with a qualified name.");
    }
    if (isTemporaryFunction) {
        FunctionDefinition funcDefinition = funcDefFactory.createFunctionDefinition(functionName, new CatalogFunctionImpl(className, FunctionLanguage.JAVA));
        return new CreateTempSystemFunctionOperation(functionName, false, funcDefinition);
    } else {
        ObjectIdentifier identifier = parseObjectIdentifier(functionName);
        CatalogFunction catalogFunction = new CatalogFunctionImpl(className, FunctionLanguage.JAVA);
        return new CreateCatalogFunctionOperation(identifier, catalogFunction, false, false);
    }
}
Also used : CreateCatalogFunctionOperation(org.apache.flink.table.operations.ddl.CreateCatalogFunctionOperation) ValidationException(org.apache.flink.table.api.ValidationException) FunctionDefinition(org.apache.flink.table.functions.FunctionDefinition) 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 7 with CatalogFunctionImpl

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

the class HiveCatalogGenericMetadataTest method testFunctionWithNonExistClass.

// ------ functions ------
@Test
public void testFunctionWithNonExistClass() throws Exception {
    // to make sure hive catalog doesn't check function class
    catalog.createDatabase(db1, createDb(), false);
    CatalogFunction catalogFunction = new CatalogFunctionImpl("non.exist.scala.class", FunctionLanguage.SCALA);
    catalog.createFunction(path1, catalogFunction, false);
    assertEquals(catalogFunction.getClassName(), catalog.getFunction(path1).getClassName());
    assertEquals(catalogFunction.getFunctionLanguage(), catalog.getFunction(path1).getFunctionLanguage());
    // alter the function
    catalogFunction = new CatalogFunctionImpl("non.exist.java.class", FunctionLanguage.JAVA);
    catalog.alterFunction(path1, catalogFunction, false);
    assertEquals(catalogFunction.getClassName(), catalog.getFunction(path1).getClassName());
    assertEquals(catalogFunction.getFunctionLanguage(), catalog.getFunction(path1).getFunctionLanguage());
    catalogFunction = new CatalogFunctionImpl("non.exist.python.class", FunctionLanguage.PYTHON);
    catalog.alterFunction(path1, catalogFunction, false);
    assertEquals(catalogFunction.getClassName(), catalog.getFunction(path1).getClassName());
    assertEquals(catalogFunction.getFunctionLanguage(), catalog.getFunction(path1).getFunctionLanguage());
}
Also used : CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl) Test(org.junit.Test)

Example 8 with CatalogFunctionImpl

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

the class SqlToOperationConverterTest method testCreateTableWithWatermark.

@Test
public void testCreateTableWithWatermark() throws FunctionAlreadyExistException, DatabaseNotExistException {
    CatalogFunction cf = new CatalogFunctionImpl(JavaUserDefinedScalarFunctions.JavaFunc5.class.getName());
    catalog.createFunction(ObjectPath.fromString("default.myfunc"), cf, true);
    final String sql = "create table source_table(\n" + "  a int,\n" + "  b bigint,\n" + "  c timestamp(3),\n" + "  watermark for `c` as myfunc(c, 1) - interval '5' second\n" + ") with (\n" + "  'connector.type' = 'kafka')\n";
    final FlinkPlannerImpl planner = getPlannerBySqlDialect(SqlDialect.DEFAULT);
    final CalciteParser parser = getParserBySqlDialect(SqlDialect.DEFAULT);
    SqlNode node = parser.parse(sql);
    assertThat(node).isInstanceOf(SqlCreateTable.class);
    Operation operation = SqlToOperationConverter.convert(planner, catalogManager, node).get();
    assertThat(operation).isInstanceOf(CreateTableOperation.class);
    CreateTableOperation op = (CreateTableOperation) operation;
    CatalogTable catalogTable = op.getCatalogTable();
    Map<String, String> properties = catalogTable.toProperties();
    Map<String, String> expected = new HashMap<>();
    expected.put("schema.0.name", "a");
    expected.put("schema.0.data-type", "INT");
    expected.put("schema.1.name", "b");
    expected.put("schema.1.data-type", "BIGINT");
    expected.put("schema.2.name", "c");
    expected.put("schema.2.data-type", "TIMESTAMP(3)");
    expected.put("schema.watermark.0.rowtime", "c");
    expected.put("schema.watermark.0.strategy.expr", "`builtin`.`default`.`myfunc`(`c`, 1) - INTERVAL '5' SECOND");
    expected.put("schema.watermark.0.strategy.data-type", "TIMESTAMP(3)");
    expected.put("connector.type", "kafka");
    assertThat(properties).isEqualTo(expected);
}
Also used : HashMap(java.util.HashMap) FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) CatalogTable(org.apache.flink.table.catalog.CatalogTable) CatalogFunctionImpl(org.apache.flink.table.catalog.CatalogFunctionImpl) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) SqlNode(org.apache.calcite.sql.SqlNode) Test(org.junit.Test)

Aggregations

CatalogFunctionImpl (org.apache.flink.table.catalog.CatalogFunctionImpl)8 CatalogFunction (org.apache.flink.table.catalog.CatalogFunction)7 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 ValidationException (org.apache.flink.table.api.ValidationException)2 CatalogTable (org.apache.flink.table.catalog.CatalogTable)2 FunctionLanguage (org.apache.flink.table.catalog.FunctionLanguage)2 UnresolvedIdentifier (org.apache.flink.table.catalog.UnresolvedIdentifier)2 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)2 CreateCatalogFunctionOperation (org.apache.flink.table.operations.ddl.CreateCatalogFunctionOperation)2 SqlNode (org.apache.calcite.sql.SqlNode)1 TableSchema (org.apache.flink.table.api.TableSchema)1 CatalogTableImpl (org.apache.flink.table.catalog.CatalogTableImpl)1 ObjectPath (org.apache.flink.table.catalog.ObjectPath)1 DatabaseNotExistException (org.apache.flink.table.catalog.exceptions.DatabaseNotExistException)1 FunctionAlreadyExistException (org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException)1 FunctionNotExistException (org.apache.flink.table.catalog.exceptions.FunctionNotExistException)1 PartitionAlreadyExistsException (org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException)1 FunctionDefinition (org.apache.flink.table.functions.FunctionDefinition)1