Search in sources :

Example 1 with RowExpressionDomainTranslator

use of com.facebook.presto.sql.relational.RowExpressionDomainTranslator in project presto by prestodb.

the class TestDomainTranslator method setup.

@BeforeClass
public void setup() {
    metadata = createTestMetadataManager();
    domainTranslator = new RowExpressionDomainTranslator(metadata);
    columnExtractor = new SubfieldExtractor(new FunctionResolution(metadata.getFunctionAndTypeManager()), TEST_EXPRESSION_OPTIMIZER, new TestingConnectorSession(new HiveSessionProperties(new HiveClientConfig().setRangeFiltersOnSubscriptsEnabled(true), new OrcFileWriterConfig(), new ParquetFileWriterConfig(), new CacheConfig()).getSessionProperties())).toColumnExtractor();
}
Also used : RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) CacheConfig(com.facebook.presto.cache.CacheConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with RowExpressionDomainTranslator

use of com.facebook.presto.sql.relational.RowExpressionDomainTranslator in project presto by prestodb.

the class TestRowExpressionDomainTranslator method setup.

@BeforeClass
public void setup() {
    metadata = createTestMetadataManager();
    domainTranslator = new RowExpressionDomainTranslator(metadata);
}
Also used : RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with RowExpressionDomainTranslator

use of com.facebook.presto.sql.relational.RowExpressionDomainTranslator in project presto by prestodb.

the class MaterializedViewOptimizationRewriteUtils method getQueryWithMaterializedViewOptimization.

private static Query getQueryWithMaterializedViewOptimization(Metadata metadata, Session session, SqlParser sqlParser, AccessControl accessControl, Query statement, QualifiedObjectName materializedViewQualifiedObjectName) {
    ConnectorMaterializedViewDefinition materializedView = metadata.getMaterializedView(session, materializedViewQualifiedObjectName).get();
    Table materializedViewTable = new Table(QualifiedName.of(materializedView.getTable()));
    Query materializedViewDefinition = (Query) sqlParser.createStatement(materializedView.getOriginalSql());
    return (Query) new MaterializedViewQueryOptimizer(metadata, session, sqlParser, accessControl, new RowExpressionDomainTranslator(metadata), materializedViewTable, materializedViewDefinition).rewrite(statement);
}
Also used : MaterializedViewQueryOptimizer(com.facebook.presto.sql.analyzer.MaterializedViewQueryOptimizer) Table(com.facebook.presto.sql.tree.Table) Query(com.facebook.presto.sql.tree.Query) RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition)

Example 4 with RowExpressionDomainTranslator

use of com.facebook.presto.sql.relational.RowExpressionDomainTranslator in project presto by prestodb.

the class TestRowExpressionDomainTranslator method testLegacyCharComparedToVarcharExpression.

@Test
public void testLegacyCharComparedToVarcharExpression() {
    metadata = createTestMetadataManager(new FeaturesConfig().setLegacyCharToVarcharCoercion(true));
    domainTranslator = new RowExpressionDomainTranslator(metadata);
    String maxCodePoint = new String(Character.toChars(Character.MAX_CODE_POINT));
    // greater than or equal
    testSimpleComparison(greaterThanOrEqual(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Range.greaterThan(createCharType(10), utf8Slice("123456788" + maxCodePoint)));
    testSimpleComparison(greaterThanOrEqual(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Range.greaterThanOrEqual(createCharType(10), Slices.utf8Slice("1234567890")));
    testSimpleComparison(greaterThanOrEqual(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Range.greaterThan(createCharType(10), Slices.utf8Slice("1234567890")));
    // greater than
    testSimpleComparison(greaterThan(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Range.greaterThan(createCharType(10), utf8Slice("123456788" + maxCodePoint)));
    testSimpleComparison(greaterThan(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Range.greaterThan(createCharType(10), Slices.utf8Slice("1234567890")));
    testSimpleComparison(greaterThan(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Range.greaterThan(createCharType(10), Slices.utf8Slice("1234567890")));
    // less than or equal
    testSimpleComparison(lessThanOrEqual(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Range.lessThanOrEqual(createCharType(10), utf8Slice("123456788" + maxCodePoint)));
    testSimpleComparison(lessThanOrEqual(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Range.lessThanOrEqual(createCharType(10), Slices.utf8Slice("1234567890")));
    testSimpleComparison(lessThanOrEqual(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Range.lessThanOrEqual(createCharType(10), Slices.utf8Slice("1234567890")));
    // less than
    testSimpleComparison(lessThan(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Range.lessThanOrEqual(createCharType(10), utf8Slice("123456788" + maxCodePoint)));
    testSimpleComparison(lessThan(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Range.lessThan(createCharType(10), Slices.utf8Slice("1234567890")));
    testSimpleComparison(lessThan(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Range.lessThanOrEqual(createCharType(10), Slices.utf8Slice("1234567890")));
    // equal
    testSimpleComparison(equal(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Domain.none(createCharType(10)));
    testSimpleComparison(equal(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Range.equal(createCharType(10), Slices.utf8Slice("1234567890")));
    testSimpleComparison(equal(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Domain.none(createCharType(10)));
    // not equal
    testSimpleComparison(notEqual(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Domain.notNull(createCharType(10)));
    testSimpleComparison(notEqual(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Domain.create(ValueSet.ofRanges(Range.lessThan(createCharType(10), Slices.utf8Slice("1234567890")), Range.greaterThan(createCharType(10), Slices.utf8Slice("1234567890"))), false));
    testSimpleComparison(notEqual(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Domain.notNull(createCharType(10)));
    // is distinct from
    testSimpleComparison(isDistinctFrom(cast(C_CHAR, VARCHAR), stringLiteral("123456789")), C_CHAR, Domain.all(createCharType(10)));
    testSimpleComparison(isDistinctFrom(cast(C_CHAR, VARCHAR), stringLiteral("1234567890")), C_CHAR, Domain.create(ValueSet.ofRanges(Range.lessThan(createCharType(10), Slices.utf8Slice("1234567890")), Range.greaterThan(createCharType(10), Slices.utf8Slice("1234567890"))), true));
    testSimpleComparison(isDistinctFrom(cast(C_CHAR, VARCHAR), stringLiteral("12345678901")), C_CHAR, Domain.all(createCharType(10)));
}
Also used : FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) Test(org.testng.annotations.Test)

Aggregations

RowExpressionDomainTranslator (com.facebook.presto.sql.relational.RowExpressionDomainTranslator)4 BeforeClass (org.testng.annotations.BeforeClass)2 CacheConfig (com.facebook.presto.cache.CacheConfig)1 ConnectorMaterializedViewDefinition (com.facebook.presto.spi.ConnectorMaterializedViewDefinition)1 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)1 MaterializedViewQueryOptimizer (com.facebook.presto.sql.analyzer.MaterializedViewQueryOptimizer)1 FunctionResolution (com.facebook.presto.sql.relational.FunctionResolution)1 Query (com.facebook.presto.sql.tree.Query)1 Table (com.facebook.presto.sql.tree.Table)1 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)1 Test (org.testng.annotations.Test)1