use of org.apache.flink.table.api.TableConfig in project flink by apache.
the class StreamTableEnvironmentImplTest method getStreamTableEnvironment.
private StreamTableEnvironmentImpl getStreamTableEnvironment(StreamExecutionEnvironment env, DataStreamSource<Integer> elements) {
TableConfig tableConfig = new TableConfig();
CatalogManager catalogManager = CatalogManagerMocks.createEmptyCatalogManager();
ModuleManager moduleManager = new ModuleManager();
return new StreamTableEnvironmentImpl(catalogManager, moduleManager, new FunctionCatalog(tableConfig, catalogManager, moduleManager), tableConfig, env, new TestPlanner(elements.getTransformation()), new ExecutorMock(), true, this.getClass().getClassLoader());
}
use of org.apache.flink.table.api.TableConfig in project flink by apache.
the class SortCodeGeneratorTest method getSortBaseWithNulls.
public static Tuple2<NormalizedKeyComputer, RecordComparator> getSortBaseWithNulls(String namePrefix, RowType inputType, SortSpec sortSpec) {
SortCodeGenerator generator = new SortCodeGenerator(new TableConfig(), inputType, sortSpec);
GeneratedNormalizedKeyComputer computer = generator.generateNormalizedKeyComputer(namePrefix + "Computer");
GeneratedRecordComparator comparator = generator.generateRecordComparator(namePrefix + "Comparator");
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return new Tuple2<>(computer.newInstance(cl), comparator.newInstance(cl));
}
use of org.apache.flink.table.api.TableConfig in project flink by apache.
the class CodeSplitTest method testJoinCondition.
@Test
public void testJoinCondition() {
int numFields = 200;
FlinkTypeFactory typeFactory = FlinkTypeFactory.INSTANCE();
RexBuilder builder = new RexBuilder(typeFactory);
RelDataType intType = typeFactory.createFieldTypeFromLogicalType(new IntType());
RexNode[] conditions = new RexNode[numFields];
for (int i = 0; i < numFields; i++) {
conditions[i] = builder.makeCall(SqlStdOperatorTable.LESS_THAN, new RexInputRef(i, intType), new RexInputRef(numFields + i, intType));
}
RexNode joinCondition = builder.makeCall(SqlStdOperatorTable.AND, conditions);
RowType rowType = getIntRowType(numFields);
GenericRowData rowData1 = new GenericRowData(numFields);
GenericRowData rowData2 = new GenericRowData(numFields);
Random random = new Random();
for (int i = 0; i < numFields; i++) {
rowData1.setField(i, 0);
rowData2.setField(i, 1);
}
boolean result = random.nextBoolean();
if (!result) {
rowData1.setField(random.nextInt(numFields), 1);
}
Consumer<TableConfig> consumer = tableConfig -> {
JoinCondition instance = JoinUtil.generateConditionFunction(tableConfig, joinCondition, rowType, rowType).newInstance(classLoader);
for (int i = 0; i < 100; i++) {
Assert.assertEquals(result, instance.apply(rowData1, rowData2));
}
};
runTest(consumer);
}
use of org.apache.flink.table.api.TableConfig in project flink by apache.
the class CodeSplitTest method testHashFunction.
@Test
public void testHashFunction() {
int numFields = 1000;
RowType rowType = getIntRowType(numFields);
int[] hashFields = new int[numFields];
for (int i = 0; i < numFields; i++) {
hashFields[i] = i;
}
GenericRowData rowData = new GenericRowData(numFields);
for (int i = 0; i < numFields; i++) {
rowData.setField(i, i);
}
Consumer<TableConfig> consumer = tableConfig -> {
HashFunction instance = HashCodeGenerator.generateRowHash(new CodeGeneratorContext(tableConfig), rowType, "", hashFields).newInstance(classLoader);
for (int i = 0; i < 100; i++) {
Assert.assertEquals(-1433414860, instance.hashCode(rowData));
}
};
runTest(consumer);
}
use of org.apache.flink.table.api.TableConfig in project flink by apache.
the class KeySelectorUtil method getRowDataSelector.
/**
* Create a RowDataKeySelector to extract keys from DataStream which type is {@link
* InternalTypeInfo} of {@link RowData}.
*
* @param keyFields key fields
* @param rowType type of DataStream to extract keys
* @return the RowDataKeySelector to extract keys from DataStream which type is {@link
* InternalTypeInfo} of {@link RowData}.
*/
public static RowDataKeySelector getRowDataSelector(int[] keyFields, InternalTypeInfo<RowData> rowType) {
if (keyFields.length > 0) {
LogicalType[] inputFieldTypes = rowType.toRowFieldTypes();
LogicalType[] keyFieldTypes = new LogicalType[keyFields.length];
for (int i = 0; i < keyFields.length; ++i) {
keyFieldTypes[i] = inputFieldTypes[keyFields[i]];
}
// do not provide field names for the result key type,
// because we may have duplicate key fields and the field names may conflict
RowType returnType = RowType.of(keyFieldTypes);
RowType inputType = rowType.toRowType();
GeneratedProjection generatedProjection = ProjectionCodeGenerator.generateProjection(CodeGeneratorContext.apply(new TableConfig()), "KeyProjection", inputType, returnType, keyFields);
InternalTypeInfo<RowData> keyRowType = InternalTypeInfo.of(returnType);
return new BinaryRowDataKeySelector(keyRowType, generatedProjection);
} else {
return EmptyRowDataKeySelector.INSTANCE;
}
}
Aggregations