org.apache.flink.table.expressions.BinaryComparison Java Examples

The following examples show how to use org.apache.flink.table.expressions.BinaryComparison. 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: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private Object getLiteral(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).value();
	} else {
		return ((Literal) comp.left()).value();
	}
}
 
Example #2
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private Object getLiteral(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).value();
	} else {
		return ((Literal) comp.left()).value();
	}
}
 
Example #3
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private PredicateLeaf.Type getLiteralType(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return toOrcType(((Literal) comp.right()).resultType());
	} else {
		return toOrcType(((Literal) comp.left()).resultType());
	}
}
 
Example #4
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private String getColumnName(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Attribute) comp.left()).name();
	} else {
		return ((Attribute) comp.right()).name();
	}
}
 
Example #5
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean literalOnRight(BinaryComparison comp) {
	if (comp.left() instanceof Literal && comp.right() instanceof Attribute) {
		return false;
	} else if (comp.left() instanceof Attribute && comp.right() instanceof Literal) {
		return true;
	} else {
		throw new RuntimeException("Invalid binary comparison.");
	}
}
 
Example #6
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private String getColumnName(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Attribute) comp.left()).name();
	} else {
		return ((Attribute) comp.right()).name();
	}
}
 
Example #7
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private Object getLiteral(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).value();
	} else {
		return ((Literal) comp.left()).value();
	}
}
 
Example #8
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeInformation<?> getLiteralType(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).resultType();
	} else {
		return ((Literal) comp.left()).resultType();
	}
}
 
Example #9
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean literalOnRight(BinaryComparison comp) {
	if (comp.left() instanceof Literal && comp.right() instanceof Attribute) {
		return false;
	} else if (comp.left() instanceof Attribute && comp.right() instanceof Literal) {
		return true;
	} else {
		throw new RuntimeException("Invalid binary comparison.");
	}
}
 
Example #10
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nullable
private Tuple2<Column, Comparable> extractColumnAndLiteral(BinaryComparison comp) {
	TypeInformation<?> typeInfo = getLiteralType(comp);
	String columnName = getColumnName(comp);

	// fetch literal and ensure it is comparable
	Object value = getLiteral(comp);
	// validate that literal is comparable
	if (!(value instanceof Comparable)) {
		LOG.warn("Encountered a non-comparable literal of type {}." +
			"Cannot push predicate [{}] into ParquetTablesource." +
			"This is a bug and should be reported.", value.getClass().getCanonicalName(), comp);
		return null;
	}

	if (typeInfo == BasicTypeInfo.BYTE_TYPE_INFO ||
		typeInfo == BasicTypeInfo.SHORT_TYPE_INFO ||
		typeInfo == BasicTypeInfo.INT_TYPE_INFO) {
		return new Tuple2<>(FilterApi.intColumn(columnName), (Integer) value);
	} else if (typeInfo == BasicTypeInfo.LONG_TYPE_INFO) {
		return new Tuple2<>(FilterApi.longColumn(columnName), (Long) value);
	} else if (typeInfo == BasicTypeInfo.FLOAT_TYPE_INFO) {
		return new Tuple2<>(FilterApi.floatColumn(columnName), (Float) value);
	} else if (typeInfo == BasicTypeInfo.BOOLEAN_TYPE_INFO) {
		return new Tuple2<>(FilterApi.booleanColumn(columnName), (Boolean) value);
	} else if (typeInfo == BasicTypeInfo.DOUBLE_TYPE_INFO) {
		return new Tuple2<>(FilterApi.doubleColumn(columnName), (Double) value);
	} else if (typeInfo == BasicTypeInfo.STRING_TYPE_INFO) {
		return new Tuple2<>(FilterApi.binaryColumn(columnName), Binary.fromString((String) value));
	} else {
		// unsupported type
		return null;
	}
}
 
Example #11
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private String getColumnName(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Attribute) comp.left()).name();
	} else {
		return ((Attribute) comp.right()).name();
	}
}
 
Example #12
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private TypeInformation<?> getLiteralType(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).resultType();
	} else {
		return ((Literal) comp.left()).resultType();
	}
}
 
Example #13
Source File: ParquetTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean literalOnRight(BinaryComparison comp) {
	if (comp.left() instanceof Literal && comp.right() instanceof Attribute) {
		return false;
	} else if (comp.left() instanceof Attribute && comp.right() instanceof Literal) {
		return true;
	} else {
		throw new RuntimeException("Invalid binary comparison.");
	}
}
 
Example #14
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private Object getLiteral(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).value();
	} else {
		return ((Literal) comp.left()).value();
	}
}
 
Example #15
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private PredicateLeaf.Type getLiteralType(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return toOrcType(((Literal) comp.right()).resultType());
	} else {
		return toOrcType(((Literal) comp.left()).resultType());
	}
}
 
Example #16
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private String getColumnName(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Attribute) comp.left()).name();
	} else {
		return ((Attribute) comp.right()).name();
	}
}
 
Example #17
Source File: OrcTableSource.java    From flink with Apache License 2.0 5 votes vote down vote up
private boolean literalOnRight(BinaryComparison comp) {
	if (comp.left() instanceof Literal && comp.right() instanceof Attribute) {
		return false;
	} else if (comp.left() instanceof Attribute && comp.right() instanceof Literal) {
		return true;
	} else {
		throw new RuntimeException("Invalid binary comparison.");
	}
}
 
Example #18
Source File: OrcTableSource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private Object getLiteral(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Literal) comp.right()).value();
	} else {
		return ((Literal) comp.left()).value();
	}
}
 
Example #19
Source File: OrcTableSource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private PredicateLeaf.Type getLiteralType(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return toOrcType(((Literal) comp.right()).resultType());
	} else {
		return toOrcType(((Literal) comp.left()).resultType());
	}
}
 
Example #20
Source File: OrcTableSource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private String getColumnName(BinaryComparison comp) {
	if (literalOnRight(comp)) {
		return ((Attribute) comp.left()).name();
	} else {
		return ((Attribute) comp.right()).name();
	}
}
 
Example #21
Source File: OrcTableSource.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private boolean literalOnRight(BinaryComparison comp) {
	if (comp.left() instanceof Literal && comp.right() instanceof Attribute) {
		return false;
	} else if (comp.left() instanceof Attribute && comp.right() instanceof Literal) {
		return true;
	} else {
		throw new RuntimeException("Invalid binary comparison.");
	}
}
 
Example #22
Source File: OrcTableSource.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
private boolean isValid(BinaryComparison comp) {
	return (comp.left() instanceof Literal && comp.right() instanceof Attribute) ||
		(comp.left() instanceof Attribute && comp.right() instanceof Literal);
}
 
Example #23
Source File: ParquetTableSource.java    From flink with Apache License 2.0 4 votes vote down vote up
private boolean isValid(BinaryComparison comp) {
	return (comp.left() instanceof Literal && comp.right() instanceof Attribute) ||
		(comp.left() instanceof Attribute && comp.right() instanceof Literal);
}
 
Example #24
Source File: ParquetTableSource.java    From flink with Apache License 2.0 4 votes vote down vote up
private boolean isValid(BinaryComparison comp) {
	return (comp.left() instanceof Literal && comp.right() instanceof Attribute) ||
		(comp.left() instanceof Attribute && comp.right() instanceof Literal);
}
 
Example #25
Source File: OrcTableSource.java    From flink with Apache License 2.0 4 votes vote down vote up
private boolean isValid(BinaryComparison comp) {
	return (comp.left() instanceof Literal && comp.right() instanceof Attribute) ||
		(comp.left() instanceof Attribute && comp.right() instanceof Literal);
}
 
Example #26
Source File: ParquetTableSource.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nullable
private Tuple2<Column, Comparable> extractColumnAndLiteral(BinaryComparison comp) {
	String columnName = getColumnName(comp);
	ColumnPath columnPath = ColumnPath.fromDotString(columnName);
	TypeInformation<?> typeInfo = null;
	try {
		Type type = parquetSchema.getType(columnPath.toArray());
		typeInfo = ParquetSchemaConverter.convertParquetTypeToTypeInfo(type);
	} catch (InvalidRecordException e) {
		LOG.error("Pushed predicate on undefined field name {} in schema", columnName);
		return null;
	}

	// fetch literal and ensure it is comparable
	Object value = getLiteral(comp);
	// validate that literal is comparable
	if (!(value instanceof Comparable)) {
		LOG.warn("Encountered a non-comparable literal of type {}." +
			"Cannot push predicate [{}] into ParquetTablesource." +
			"This is a bug and should be reported.", value.getClass().getCanonicalName(), comp);
		return null;
	}

	if (typeInfo == BasicTypeInfo.BYTE_TYPE_INFO ||
		typeInfo == BasicTypeInfo.SHORT_TYPE_INFO ||
		typeInfo == BasicTypeInfo.INT_TYPE_INFO) {
		return new Tuple2<>(FilterApi.intColumn(columnName), ((Number) value).intValue());
	} else if (typeInfo == BasicTypeInfo.LONG_TYPE_INFO) {
		return new Tuple2<>(FilterApi.longColumn(columnName), ((Number) value).longValue());
	} else if (typeInfo == BasicTypeInfo.FLOAT_TYPE_INFO) {
		return new Tuple2<>(FilterApi.floatColumn(columnName), ((Number) value).floatValue());
	} else if (typeInfo == BasicTypeInfo.BOOLEAN_TYPE_INFO) {
		return new Tuple2<>(FilterApi.booleanColumn(columnName), (Boolean) value);
	} else if (typeInfo == BasicTypeInfo.DOUBLE_TYPE_INFO) {
		return new Tuple2<>(FilterApi.doubleColumn(columnName), ((Number) value).doubleValue());
	} else if (typeInfo == BasicTypeInfo.STRING_TYPE_INFO) {
		return new Tuple2<>(FilterApi.binaryColumn(columnName), Binary.fromString((String) value));
	} else {
		// unsupported type
		return null;
	}
}
 
Example #27
Source File: OrcTableSource.java    From flink with Apache License 2.0 4 votes vote down vote up
private boolean isValid(BinaryComparison comp) {
	return (comp.left() instanceof Literal && comp.right() instanceof Attribute) ||
		(comp.left() instanceof Attribute && comp.right() instanceof Literal);
}