use of org.apache.flink.table.expressions.FieldReferenceExpression in project flink by apache.
the class LogicalWindowJsonSerializer method serialize.
@Override
public void serialize(LogicalWindow logicalWindow, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
gen.writeStartObject();
if (logicalWindow instanceof TumblingGroupWindow) {
TumblingGroupWindow window = (TumblingGroupWindow) logicalWindow;
gen.writeStringField(FIELD_NAME_KIND, KIND_TUMBLING);
serializerProvider.defaultSerializeField(FIELD_NAME_ALIAS, window.aliasAttribute(), gen);
FieldReferenceExpression timeField = logicalWindow.timeAttribute();
serializeFieldReferenceExpression(timeField, gen, serializerProvider);
ValueLiteralExpression size = window.size();
if (hasTimeIntervalType(size)) {
Duration duration = toDuration(size);
gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, true);
gen.writeObjectField(FIELD_NAME_SIZE, duration);
} else {
Long duration = toLong(size);
gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, false);
gen.writeNumberField(FIELD_NAME_SIZE, duration);
}
} else if (logicalWindow instanceof SlidingGroupWindow) {
SlidingGroupWindow window = (SlidingGroupWindow) logicalWindow;
gen.writeStringField(FIELD_NAME_KIND, KIND_SLIDING);
serializerProvider.defaultSerializeField(FIELD_NAME_ALIAS, window.aliasAttribute(), gen);
serializeFieldReferenceExpression(window.timeAttribute(), gen, serializerProvider);
ValueLiteralExpression size = window.size();
if (hasTimeIntervalType(size)) {
Duration duration = toDuration(size);
gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, true);
gen.writeObjectField(FIELD_NAME_SIZE, duration);
gen.writeObjectField(FIELD_NAME_SLIDE, toDuration(window.slide()));
} else {
Long duration = toLong(size);
gen.writeBooleanField(FIELD_NAME_IS_TIME_WINDOW, false);
gen.writeObjectField(FIELD_NAME_SIZE, duration);
gen.writeObjectField(FIELD_NAME_SLIDE, toLong(window.slide()));
}
} else if (logicalWindow instanceof SessionGroupWindow) {
gen.writeStringField(FIELD_NAME_KIND, KIND_SESSION);
SessionGroupWindow window = (SessionGroupWindow) logicalWindow;
serializerProvider.defaultSerializeField(FIELD_NAME_ALIAS, window.aliasAttribute(), gen);
serializeFieldReferenceExpression(window.timeAttribute(), gen, serializerProvider);
gen.writeObjectField(FIELD_NAME_GAP, toDuration(window.gap()));
} else {
throw new TableException("Unknown LogicalWindow: " + logicalWindow);
}
gen.writeEndObject();
}
use of org.apache.flink.table.expressions.FieldReferenceExpression in project flink by apache.
the class HiveTableUtilTest method testMakePartitionFilter.
@Test
public void testMakePartitionFilter() {
List<String> partColNames = Arrays.asList("p1", "p2", "p3");
ResolvedExpression p1Ref = new FieldReferenceExpression("p1", DataTypes.INT(), 0, 2);
ResolvedExpression p2Ref = new FieldReferenceExpression("p2", DataTypes.STRING(), 0, 3);
ResolvedExpression p3Ref = new FieldReferenceExpression("p3", DataTypes.DOUBLE(), 0, 4);
ResolvedExpression p1Exp = CallExpression.permanent(BuiltInFunctionDefinitions.EQUALS, Arrays.asList(p1Ref, valueLiteral(1)), DataTypes.BOOLEAN());
ResolvedExpression p2Exp = CallExpression.permanent(BuiltInFunctionDefinitions.EQUALS, Arrays.asList(p2Ref, valueLiteral("a", DataTypes.STRING().notNull())), DataTypes.BOOLEAN());
ResolvedExpression p3Exp = CallExpression.permanent(BuiltInFunctionDefinitions.EQUALS, Arrays.asList(p3Ref, valueLiteral(1.1)), DataTypes.BOOLEAN());
Optional<String> filter = HiveTableUtil.makePartitionFilter(2, partColNames, Arrays.asList(p1Exp), hiveShim);
assertEquals("(p1 = 1)", filter.orElse(null));
filter = HiveTableUtil.makePartitionFilter(2, partColNames, Arrays.asList(p1Exp, p3Exp), hiveShim);
assertEquals("(p1 = 1) and (p3 = 1.1)", filter.orElse(null));
filter = HiveTableUtil.makePartitionFilter(2, partColNames, Arrays.asList(p2Exp, CallExpression.permanent(BuiltInFunctionDefinitions.OR, Arrays.asList(p1Exp, p3Exp), DataTypes.BOOLEAN())), hiveShim);
assertEquals("(p2 = 'a') and ((p1 = 1) or (p3 = 1.1))", filter.orElse(null));
}
use of org.apache.flink.table.expressions.FieldReferenceExpression in project flink by apache.
the class OrcFileSystemFilterTest method testApplyPredicate.
@Test
@SuppressWarnings("unchecked")
public void testApplyPredicate() {
List<ResolvedExpression> args = new ArrayList<>();
// equal
FieldReferenceExpression fieldReferenceExpression = new FieldReferenceExpression("long1", DataTypes.BIGINT(), 0, 0);
ValueLiteralExpression valueLiteralExpression = new ValueLiteralExpression(10);
args.add(fieldReferenceExpression);
args.add(valueLiteralExpression);
CallExpression equalExpression = CallExpression.permanent(BuiltInFunctionDefinitions.EQUALS, args, DataTypes.BOOLEAN());
OrcFilters.Predicate predicate1 = OrcFilters.toOrcPredicate(equalExpression);
OrcFilters.Predicate predicate2 = new OrcFilters.Equals("long1", PredicateLeaf.Type.LONG, 10);
assertTrue(predicate1.toString().equals(predicate2.toString()));
// greater than
CallExpression greaterExpression = CallExpression.permanent(BuiltInFunctionDefinitions.GREATER_THAN, args, DataTypes.BOOLEAN());
OrcFilters.Predicate predicate3 = OrcFilters.toOrcPredicate(greaterExpression);
OrcFilters.Predicate predicate4 = new OrcFilters.Not(new OrcFilters.LessThanEquals("long1", PredicateLeaf.Type.LONG, 10));
assertTrue(predicate3.toString().equals(predicate4.toString()));
// less than
CallExpression lessExpression = CallExpression.permanent(BuiltInFunctionDefinitions.LESS_THAN, args, DataTypes.BOOLEAN());
OrcFilters.Predicate predicate5 = OrcFilters.toOrcPredicate(lessExpression);
OrcFilters.Predicate predicate6 = new OrcFilters.LessThan("long1", PredicateLeaf.Type.LONG, 10);
assertTrue(predicate5.toString().equals(predicate6.toString()));
}
use of org.apache.flink.table.expressions.FieldReferenceExpression in project flink by apache.
the class QueryOperationTest method testSummaryString.
@Test
public void testSummaryString() {
ResolvedSchema schema = ResolvedSchema.physical(Collections.singletonList("a"), Collections.singletonList(DataTypes.INT()));
ProjectQueryOperation tableOperation = new ProjectQueryOperation(Collections.singletonList(new FieldReferenceExpression("a", DataTypes.INT(), 0, 0)), new SourceQueryOperation(ContextResolvedTable.temporary(ObjectIdentifier.of("cat1", "db1", "tab1"), new ResolvedCatalogTable(CatalogTable.of(Schema.newBuilder().build(), null, Collections.emptyList(), Collections.emptyMap()), schema))), schema);
SetQueryOperation unionQueryOperation = new SetQueryOperation(tableOperation, tableOperation, SetQueryOperation.SetQueryOperationType.UNION, true, schema);
assertEquals("Union: (all: [true])\n" + " Project: (projections: [a])\n" + " CatalogTable: (identifier: [cat1.db1.tab1], fields: [a])\n" + " Project: (projections: [a])\n" + " CatalogTable: (identifier: [cat1.db1.tab1], fields: [a])", unionQueryOperation.asSummaryString());
}
use of org.apache.flink.table.expressions.FieldReferenceExpression in project flink by apache.
the class AggregateOperationFactory method getValidatedTimeAttribute.
private FieldReferenceExpression getValidatedTimeAttribute(GroupWindow window, ExpressionResolver resolver) {
List<ResolvedExpression> timeFieldExprs = resolver.resolve(singletonList(window.getTimeField()));
if (timeFieldExprs.size() != 1) {
throw new ValidationException("A group window only supports a single time field column.");
}
Expression timeFieldExpr = timeFieldExprs.get(0);
if (!(timeFieldExpr instanceof FieldReferenceExpression)) {
throw new ValidationException("A group window expects a time attribute for grouping.");
}
FieldReferenceExpression timeField = (FieldReferenceExpression) timeFieldExpr;
final LogicalType timeFieldType = timeField.getOutputDataType().getLogicalType();
validateTimeAttributeType(timeFieldType);
return timeField;
}
Aggregations