org.apache.flink.table.functions.TableAggregateFunction Java Examples

The following examples show how to use org.apache.flink.table.functions.TableAggregateFunction. 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: FunctionCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
public <T, ACC> void registerAggregateFunction(
		String name,
		UserDefinedAggregateFunction<T, ACC> function,
		TypeInformation<T> resultType,
		TypeInformation<ACC> accType) {
	// check if class not Scala object
	UserFunctionsTypeHelper.validateNotSingleton(function.getClass());
	// check if class could be instantiated
	UserFunctionsTypeHelper.validateInstantiation(function.getClass());

	final FunctionDefinition definition;
	if (function instanceof AggregateFunction) {
		definition = new AggregateFunctionDefinition(
			name,
			(AggregateFunction<?, ?>) function,
			resultType,
			accType);
	} else if (function instanceof TableAggregateFunction) {
		definition = new TableAggregateFunctionDefinition(
			name,
			(TableAggregateFunction<?, ?>) function,
			resultType,
			accType);
	} else {
		throw new TableException("Unknown function class: " + function.getClass());
	}

	registerFunction(
		name,
		definition
	);
}
 
Example #2
Source File: StreamTableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T, ACC> void registerFunction(String name, TableAggregateFunction<T, ACC> tableAggregateFunction) {
	TypeInformation<T> typeInfo = UserFunctionsTypeHelper.getReturnTypeOfAggregateFunction(
		tableAggregateFunction);
	TypeInformation<ACC> accTypeInfo = UserFunctionsTypeHelper
		.getAccumulatorTypeOfAggregateFunction(tableAggregateFunction);

	functionCatalog.registerAggregateFunction(
		name,
		tableAggregateFunction,
		typeInfo,
		accTypeInfo
	);
}
 
Example #3
Source File: TypeInferenceExtractor.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Extracts a type inference from a {@link TableAggregateFunction}.
 */
public static TypeInference forTableAggregateFunction(
		DataTypeFactory typeFactory,
		Class<? extends TableAggregateFunction<?, ?>> function) {
	final FunctionMappingExtractor mappingExtractor = new FunctionMappingExtractor(
		typeFactory,
		function,
		UserDefinedFunctionHelper.TABLE_AGGREGATE_ACCUMULATE,
		createParameterSignatureExtraction(1),
		createGenericResultExtraction(TableAggregateFunction.class, 1),
		createGenericResultExtraction(TableAggregateFunction.class, 0),
		createParameterWithAccumulatorVerification());
	return extractTypeInference(mappingExtractor);
}
 
Example #4
Source File: FunctionCatalog.java    From flink with Apache License 2.0 5 votes vote down vote up
public <T, ACC> void registerTempSystemAggregateFunction(
		String name,
		UserDefinedAggregateFunction<T, ACC> function,
		TypeInformation<T> resultType,
		TypeInformation<ACC> accType) {
	UserDefinedFunctionHelper.prepareInstance(config, function);

	final FunctionDefinition definition;
	if (function instanceof AggregateFunction) {
		definition = new AggregateFunctionDefinition(
			name,
			(AggregateFunction<?, ?>) function,
			resultType,
			accType);
	} else if (function instanceof TableAggregateFunction) {
		definition = new TableAggregateFunctionDefinition(
			name,
			(TableAggregateFunction<?, ?>) function,
			resultType,
			accType);
	} else {
		throw new TableException("Unknown function class: " + function.getClass());
	}

	registerTempSystemFunction(
		name,
		definition
	);
}
 
Example #5
Source File: StreamTableEnvironmentImpl.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public <T, ACC> void registerFunction(String name, TableAggregateFunction<T, ACC> tableAggregateFunction) {
	TypeInformation<T> typeInfo = UserDefinedFunctionHelper.getReturnTypeOfAggregateFunction(
		tableAggregateFunction);
	TypeInformation<ACC> accTypeInfo = UserDefinedFunctionHelper
		.getAccumulatorTypeOfAggregateFunction(tableAggregateFunction);

	functionCatalog.registerTempSystemAggregateFunction(
		name,
		tableAggregateFunction,
		typeInfo,
		accTypeInfo
	);
}
 
Example #6
Source File: Flink111Shims.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTableAggregateFunction(Object btenv, String name, Object tableAggregateFunction) {
  ((StreamTableEnvironmentImpl)(btenv)).registerFunction(name, (TableAggregateFunction) tableAggregateFunction);
}
 
Example #7
Source File: Flink110Shims.java    From zeppelin with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTableAggregateFunction(Object btenv, String name, Object tableAggregateFunction) {
  ((StreamTableEnvironmentImpl)(btenv)).registerFunction(name, (TableAggregateFunction) tableAggregateFunction);
}
 
Example #8
Source File: TypeInferenceExtractorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
static TestSpec forTableAggregateFunction(Class<? extends TableAggregateFunction<?, ?>> function) {
	return forTableAggregateFunction(null, function);
}
 
Example #9
Source File: TypeInferenceExtractorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
static TestSpec forTableAggregateFunction(String description, Class<? extends TableAggregateFunction<?, ?>> function) {
	return new TestSpec(
		description == null ? function.getSimpleName() : description,
		() -> TypeInferenceExtractor.forTableAggregateFunction(new DataTypeFactoryMock(), function));
}
 
Example #10
Source File: StreamTableEnvironment.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Registers an {@link TableAggregateFunction} under a unique name in the TableEnvironment's
 * catalog. Registered functions can only be referenced in Table API.
 *
 * @param name The name under which the function is registered.
 * @param tableAggregateFunction The TableAggregateFunction to register.
 * @param <T> The type of the output value.
 * @tparam ACC The type of aggregate accumulator.
 */
<T, ACC> void registerFunction(String name, TableAggregateFunction<T, ACC> tableAggregateFunction);
 
Example #11
Source File: StreamTableEnvironment.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Registers an {@link TableAggregateFunction} under a unique name in the TableEnvironment's
 * catalog. Registered functions can only be referenced in Table API.
 *
 * @param name The name under which the function is registered.
 * @param tableAggregateFunction The TableAggregateFunction to register.
 * @param <T> The type of the output value.
 * @param <ACC> The type of aggregate accumulator.
 */
<T, ACC> void registerFunction(String name, TableAggregateFunction<T, ACC> tableAggregateFunction);