org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException Java Examples

The following examples show how to use org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
		throws FunctionAlreadyExistException, DatabaseNotExistException {
	checkNotNull(functionPath);
	checkNotNull(function);

	if (!databaseExists(functionPath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), functionPath.getDatabaseName());
	}

	if (functionExists(functionPath)) {
		if (!ignoreIfExists) {
			throw new FunctionAlreadyExistException(getName(), functionPath);
		}
	} else {
		functions.put(functionPath, function.copy());
	}
}
 
Example #2
Source File: GenericInMemoryCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void createFunction(ObjectPath path, CatalogFunction function, boolean ignoreIfExists)
		throws FunctionAlreadyExistException, DatabaseNotExistException {
	checkNotNull(path);
	checkNotNull(function);

	ObjectPath functionPath = normalize(path);

	if (!databaseExists(functionPath.getDatabaseName())) {
		throw new DatabaseNotExistException(getName(), functionPath.getDatabaseName());
	}

	if (functionExists(functionPath)) {
		if (!ignoreIfExists) {
			throw new FunctionAlreadyExistException(getName(), functionPath);
		}
	} else {
		functions.put(functionPath, function.copy());
	}
}
 
Example #3
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFunction_FunctionAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	catalog.createFunction(path1, createFunction(), false);

	assertTrue(catalog.functionExists(path1));

	// test 'ignoreIfExist' flag
	catalog.createFunction(path1, createAnotherFunction(), true);

	exception.expect(FunctionAlreadyExistException.class);
	exception.expectMessage("Function db1.t1 already exists in Catalog");
	catalog.createFunction(path1, createFunction(), false);
}
 
Example #4
Source File: CatalogTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateFunction_FunctionAlreadyExistException() throws Exception {
	catalog.createDatabase(db1, createDb(), false);
	catalog.createFunction(path1, createFunction(), false);

	assertTrue(catalog.functionExists(path1));

	// test 'ignoreIfExist' flag
	catalog.createFunction(path1, createAnotherFunction(), true);

	exception.expect(FunctionAlreadyExistException.class);
	exception.expectMessage("Function db1.t1 already exists in Catalog");
	catalog.createFunction(path1, createFunction(), false);
}
 
Example #5
Source File: SqlToOperationConverterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@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);
	assert node instanceof SqlCreateTable;
	Operation operation = SqlToOperationConverter.convert(planner, catalogManager, node).get();
	assert operation instanceof CreateTableOperation;
	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");
	assertEquals(expected, properties);
}
 
Example #6
Source File: PulsarCatalog.java    From pulsar-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists) throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
    throw new UnsupportedOperationException();
}
 
Example #7
Source File: AbstractReadOnlyCatalog.java    From bahir-flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists) throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
    throw UNSUPPORTED_ERR;
}
 
Example #8
Source File: AbstractJdbcCatalog.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists) throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
	throw new UnsupportedOperationException();
}
 
Example #9
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Create a function.
 *
 * @param functionPath      path of the function
 * @param function          the function to be created
 * @param ignoreIfExists    flag to specify behavior if a function with the given name already exists:
 *                          if set to false, it throws a FunctionAlreadyExistException,
 *                          if set to true, nothing happens.
 * @throws FunctionAlreadyExistException if the function already exist
 * @throws DatabaseNotExistException     if the given database does not exist
 * @throws CatalogException in case of any runtime exception
 */
void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
	throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException;
 
Example #10
Source File: Catalog.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Create a function.
 * Function name should be handled in a case insensitive way.
 *
 * @param functionPath      path of the function
 * @param function          the function to be created
 * @param ignoreIfExists    flag to specify behavior if a function with the given name already exists:
 *                          if set to false, it throws a FunctionAlreadyExistException,
 *                          if set to true, nothing happens.
 * @throws FunctionAlreadyExistException if the function already exist
 * @throws DatabaseNotExistException     if the given database does not exist
 * @throws CatalogException in case of any runtime exception
 */
void createFunction(ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
	throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException;