Java Code Examples for org.apache.parquet.filter2.predicate.FilterApi#booleanColumn()
The following examples show how to use
org.apache.parquet.filter2.predicate.FilterApi#booleanColumn() .
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 |
@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 2
Source File: ParquetFilters.java From iceberg with Apache License 2.0 | 4 votes |
@Override public <T> FilterPredicate predicate(BoundPredicate<T> pred) { if (!(pred.term() instanceof BoundReference)) { throw new UnsupportedOperationException("Cannot convert non-reference to Parquet filter: " + pred.term()); } Operation op = pred.op(); BoundReference<T> ref = (BoundReference<T>) pred.term(); String path = schema.idToAlias(ref.fieldId()); Literal<T> lit; if (pred.isUnaryPredicate()) { lit = null; } else if (pred.isLiteralPredicate()) { lit = pred.asLiteralPredicate().literal(); } else { throw new UnsupportedOperationException("Cannot convert to Parquet filter: " + pred); } switch (ref.type().typeId()) { case BOOLEAN: Operators.BooleanColumn col = FilterApi.booleanColumn(path); switch (op) { case EQ: return FilterApi.eq(col, getParquetPrimitive(lit)); case NOT_EQ: return FilterApi.notEq(col, getParquetPrimitive(lit)); } break; case INTEGER: case DATE: return pred(op, FilterApi.intColumn(path), getParquetPrimitive(lit)); case LONG: case TIME: case TIMESTAMP: return pred(op, FilterApi.longColumn(path), getParquetPrimitive(lit)); case FLOAT: return pred(op, FilterApi.floatColumn(path), getParquetPrimitive(lit)); case DOUBLE: return pred(op, FilterApi.doubleColumn(path), getParquetPrimitive(lit)); case STRING: case UUID: case FIXED: case BINARY: case DECIMAL: return pred(op, FilterApi.binaryColumn(path), getParquetPrimitive(lit)); } throw new UnsupportedOperationException("Cannot convert to Parquet filter: " + pred); }
Example 3
Source File: ParquetFilters.java From iceberg with Apache License 2.0 | 4 votes |
@Override public <T> FilterPredicate predicate(BoundPredicate<T> pred) { Operation op = pred.op(); BoundReference<T> ref = pred.ref(); Literal<T> lit = pred.literal(); String path = schema.idToAlias(ref.fieldId()); switch (ref.type().typeId()) { case BOOLEAN: Operators.BooleanColumn col = FilterApi.booleanColumn(schema.idToAlias(ref.fieldId())); switch (op) { case EQ: return FilterApi.eq(col, getParquetPrimitive(lit)); case NOT_EQ: return FilterApi.eq(col, getParquetPrimitive(lit)); } case INTEGER: return pred(op, FilterApi.intColumn(path), getParquetPrimitive(lit)); case LONG: return pred(op, FilterApi.longColumn(path), getParquetPrimitive(lit)); case FLOAT: return pred(op, FilterApi.floatColumn(path), getParquetPrimitive(lit)); case DOUBLE: return pred(op, FilterApi.doubleColumn(path), getParquetPrimitive(lit)); case DATE: return pred(op, FilterApi.intColumn(path), getParquetPrimitive(lit)); case TIME: return pred(op, FilterApi.longColumn(path), getParquetPrimitive(lit)); case TIMESTAMP: return pred(op, FilterApi.longColumn(path), getParquetPrimitive(lit)); case STRING: return pred(op, FilterApi.binaryColumn(path), getParquetPrimitive(lit)); case UUID: return pred(op, FilterApi.binaryColumn(path), getParquetPrimitive(lit)); case FIXED: return pred(op, FilterApi.binaryColumn(path), getParquetPrimitive(lit)); case BINARY: return pred(op, FilterApi.binaryColumn(path), getParquetPrimitive(lit)); case DECIMAL: return pred(op, FilterApi.binaryColumn(path), getParquetPrimitive(lit)); } throw new UnsupportedOperationException("Cannot convert to Parquet filter: " + pred); }
Example 4
Source File: ParquetTableSource.java From flink with Apache License 2.0 | 4 votes |
@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; } }