use of org.apache.flink.table.operations.ValuesQueryOperation in project flink by apache.
the class ValuesOperationTreeBuilderTest method testValues.
@Test
public void testValues() {
if (testSpec.exceptionMessage != null) {
thrown.expect(ValidationException.class);
thrown.expectMessage(testSpec.exceptionMessage);
}
ValuesQueryOperation operation;
if (testSpec.expectedRowType != null) {
operation = (ValuesQueryOperation) testSpec.getTreeBuilder().values(testSpec.expectedRowType, testSpec.expressions);
} else {
operation = (ValuesQueryOperation) testSpec.getTreeBuilder().values(testSpec.expressions);
}
if (testSpec.queryOperation != null) {
assertThat(operation.getResolvedSchema()).isEqualTo(testSpec.queryOperation.getResolvedSchema());
assertThat(operation.getValues()).isEqualTo(testSpec.queryOperation.getValues());
}
}
use of org.apache.flink.table.operations.ValuesQueryOperation in project flink by apache.
the class ValuesOperationFactory method create.
/**
* Creates a valid {@link ValuesQueryOperation} operation.
*
* <p>It derives a row type based on {@link LogicalTypeMerging}. It flattens any row
* constructors. It does not flatten ROWs which are a result of e.g. a function call.
*
* <p>The resulting schema can be provided manually. If it is not, the schema will be
* automatically derived from the types of the expressions.
*/
QueryOperation create(@Nullable ResolvedSchema expectedSchema, List<ResolvedExpression> resolvedExpressions, ExpressionResolver.PostResolverFactory postResolverFactory) {
List<List<ResolvedExpression>> resolvedRows = unwrapFromRowConstructor(resolvedExpressions);
if (expectedSchema != null) {
verifyAllSameSize(resolvedRows, expectedSchema.getColumnCount());
}
ResolvedSchema schema = Optional.ofNullable(expectedSchema).orElseGet(() -> extractSchema(resolvedRows));
List<List<ResolvedExpression>> castedExpressions = resolvedRows.stream().map(row -> convertTopLevelExpressionToExpectedRowType(postResolverFactory, schema.getColumnDataTypes(), row)).collect(Collectors.toList());
return new ValuesQueryOperation(castedExpressions, schema);
}
Aggregations