use of com.facebook.presto.sql.planner.LiteralEncoder in project presto by prestodb.
the class TestTupleDomainFilterUtils method setup.
@BeforeClass
public void setup() {
metadata = createTestMetadataManager();
literalEncoder = new LiteralEncoder(metadata.getBlockEncodingSerde());
}
use of com.facebook.presto.sql.planner.LiteralEncoder in project presto by prestodb.
the class SimplifyExpressions method createRewrite.
private static ExpressionRewriter createRewrite(Metadata metadata, SqlParser sqlParser) {
requireNonNull(metadata, "metadata is null");
requireNonNull(sqlParser, "sqlParser is null");
LiteralEncoder literalEncoder = new LiteralEncoder(metadata.getBlockEncodingSerde());
return (expression, context) -> rewrite(expression, context.getSession(), context.getVariableAllocator(), metadata, literalEncoder, sqlParser);
}
use of com.facebook.presto.sql.planner.LiteralEncoder in project presto by prestodb.
the class MaterializedViewUtils method generateBaseTablePredicates.
public static Map<SchemaTableName, Expression> generateBaseTablePredicates(Map<SchemaTableName, MaterializedViewStatus.MaterializedDataPredicates> predicatesFromBaseTables, Metadata metadata) {
Map<SchemaTableName, Expression> baseTablePredicates = new HashMap<>();
for (SchemaTableName baseTable : predicatesFromBaseTables.keySet()) {
MaterializedViewStatus.MaterializedDataPredicates predicatesInfo = predicatesFromBaseTables.get(baseTable);
List<String> partitionKeys = predicatesInfo.getColumnNames();
ImmutableList<Expression> keyExpressions = partitionKeys.stream().map(Identifier::new).collect(toImmutableList());
List<TupleDomain<String>> predicateDisjuncts = predicatesInfo.getPredicateDisjuncts();
Expression disjunct = null;
for (TupleDomain<String> predicateDisjunct : predicateDisjuncts) {
Expression conjunct = null;
Iterator<Expression> keyExpressionsIterator = keyExpressions.stream().iterator();
Map<String, NullableValue> predicateKeyValue = extractFixedValues(predicateDisjunct).orElseThrow(() -> new IllegalStateException("predicateKeyValue is not present!"));
for (String key : partitionKeys) {
NullableValue nullableValue = predicateKeyValue.get(key);
Expression expression;
if (nullableValue.isNull()) {
expression = new IsNullPredicate(keyExpressionsIterator.next());
} else {
LiteralEncoder literalEncoder = new LiteralEncoder(metadata.getBlockEncodingSerde());
Expression valueExpression = literalEncoder.toExpression(nullableValue.getValue(), nullableValue.getType(), false);
expression = new ComparisonExpression(EQUAL, keyExpressionsIterator.next(), valueExpression);
}
conjunct = conjunct == null ? expression : new LogicalBinaryExpression(AND, conjunct, expression);
}
disjunct = conjunct == null ? disjunct : disjunct == null ? conjunct : new LogicalBinaryExpression(OR, disjunct, conjunct);
}
// If no (fresh) partitions are found for table, that means we should not select from it
if (disjunct == null) {
disjunct = FALSE_LITERAL;
}
baseTablePredicates.put(baseTable, disjunct);
}
return baseTablePredicates;
}
use of com.facebook.presto.sql.planner.LiteralEncoder in project presto by prestodb.
the class TestScalarStatsCalculator method testVarbinaryConstant.
@Test
public void testVarbinaryConstant() {
MetadataManager metadata = createTestMetadataManager();
LiteralEncoder literalEncoder = new LiteralEncoder(metadata.getBlockEncodingSerde());
Expression expression = literalEncoder.toExpression(Slices.utf8Slice("ala ma kota"), VARBINARY);
assertCalculate(expression).distinctValuesCount(1.0).lowValueUnknown().highValueUnknown().nullsFraction(0.0);
}
Aggregations