Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Flink built-in functions should precede catalog functions, because 1)  it always give a deterministic resolution order on ambiguous reference by invoking the built-in functions 2) catalog functions can always be precisely referenced with fully/partially qualified names. In contrary, if catalog functions precede built-in functions, built-in functions can never be referenced.

4. Changes to ObjectIdentifierFunctionIdentifier


Code Block
languagejava
Class ObjectIdentifierFunctionIdentifier {
	Optional<String> catalogName;

	Optional<String> databaseName// empty for system functions
	Optional<ObjectIdentifier> oi;

	String objectNamename;
}


4. Changes to FunctionLookup interface

In order to adapt to the two cases, we propose updating FunctionLookup existing API to lookupFunction(ObjectIdentifier oi).

Calls from planner have to pass an ObjectIdentifier in which 

...

...

Otherwise, it will throw IllegalArgumentException

In case of a partially qualified name (<db_name>.<function_name>) in SQL, planner/parser should recognize it with context be padding name of the current catalog of the session first to build an ObjectIdentifier.

...

Code Block
languagejava
/**
 * Resolves a function. ObjectIdentifer should either contain both catalog and database names, or neither of them.
 *
 * @param oi objectfi identifier of function
 * @return An optional result of FunctionLookup
 */
public Optional<FunctionLookup.Result> lookupFunction(ObjectIdentifierFunctionIdentifier oifi);


5. Changes to FunctionCatalog class

...

Code Block
languagejava
private final Map<String, FunctionDefintion> tempSystemFunctions = new LinkedHashMap<>();
private final Map<ObjectIdentifier, FunctionDefintion> tempFunctions = new LinkedHashMap<>();

public void registerTemporarySystemScalarFunction(String name, ScalarFunction function) {
// put into tempSystemFunctions
}

public void registerTemporarySystemTableFunction(String name, TableFunction function) {
// put into tempSystemFunctions

}

public void registerTemporarySystemAggregateFunction(String name, AggregateFunction function) {
// put into tempSystemFunctions

}

public void registerTemporaryScalarFunction(ObjectIdentifier oi, ScalarFunction function) {
// put into tempFunctions
}

public void registerTemporaryTableFunction(ObjectIdentifier oi, TableFunction function) {
// put into tempFunctions
}

public void registerTemporaryAggregateFunction(ObjectIdentifier oi, AggregateFunction function) {
// put into tempFunctions
}

public void dropTemporarySystemFunction(String name) {}

public void dropTemporaryFunction(ObjectIdentifier oi) {}

public Optional<FunctionLookup.Result> lookupFunction(ObjectIdentifierFunctionIdentifier oifi) {
	if ((oifi.getCatalogNamegetObjectIdentifier().isPresent() && oi.getDatabaseName().isPresent())
|| (!oi.getCatalogName().isPresent() && oi.getDatabaseName().isPresent())) {
		// resolvePreciseFunctionReference(fi.getObjectIdentifier(oi));
	}

if (!oi.getCatalogName().isPresent() && !oi.getDatabaseName().isPresent()) else {
		resolveAmbiguousFunctionReference(oifi.getObjectNamegetName());
}

throw new IllegalArgumentException()/TableException();	}
}

private Optional<FunctionLookup.Result> resolvePreciseFunctionReference(ObjectIdentifier oi) {
	// resolve order:
	// 1. Temporary functions
	// 2. Catalog functions
}


private Optional<FunctionLookup.Result> resolveAmbiguousFunctionReference(String name);
	// resolve order:
	// 1. Temporary system functions
	// 2. Builtin functions
	// 3. Temporary functions, in the current catalog/db
	// 2. Catalog functions, in the current catalog/db
}

...