Search in sources :

Example 26 with MetadataManager

use of com.facebook.presto.metadata.MetadataManager in project presto by prestodb.

the class TestFilterAndProjectOperator method test.

@Test
public void test() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).build();
    MetadataManager metadata = createTestMetadataManager();
    FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
    RowExpression filter = call(BETWEEN.name(), functionAndTypeManager.resolveOperator(BETWEEN, fromTypes(BIGINT, BIGINT, BIGINT)), BOOLEAN, field(1, BIGINT), constant(10L, BIGINT), constant(19L, BIGINT));
    RowExpression field0 = field(0, VARCHAR);
    RowExpression add5 = call(ADD.name(), functionAndTypeManager.resolveOperator(ADD, fromTypes(BIGINT, BIGINT)), BIGINT, field(1, BIGINT), constant(5L, BIGINT));
    ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
    Supplier<PageProcessor> processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field0, add5));
    OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(VARCHAR, BIGINT), new DataSize(0, BYTE), 0);
    MaterializedResult expected = MaterializedResult.resultBuilder(driverContext.getSession(), VARCHAR, BIGINT).row("10", 15L).row("11", 16L).row("12", 17L).row("13", 18L).row("14", 19L).row("15", 20L).row("16", 21L).row("17", 22L).row("18", 23L).row("19", 24L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DataSize(io.airlift.units.DataSize) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 27 with MetadataManager

use of com.facebook.presto.metadata.MetadataManager in project presto by prestodb.

the class TestMetadataManager method setUp.

@BeforeClass
public void setUp() throws Exception {
    queryRunner = TpchQueryRunnerBuilder.builder().build();
    queryRunner.installPlugin(new Plugin() {

        @Override
        public Iterable<ConnectorFactory> getConnectorFactories() {
            MockConnectorFactory connectorFactory = MockConnectorFactory.builder().withListSchemaNames(session -> ImmutableList.of("UPPER_CASE_SCHEMA")).withListTables((session, schemaNameOrNull) -> {
                throw new UnsupportedOperationException();
            }).withGetViews((session, prefix) -> ImmutableMap.of()).withGetColumnHandles((session, tableHandle) -> {
                throw new UnsupportedOperationException();
            }).withGetTableStatistics(() -> {
                throw new UnsupportedOperationException();
            }).build();
            return ImmutableList.of(connectorFactory);
        }
    });
    queryRunner.createCatalog("upper_case_schema_catalog", "mock");
    metadataManager = (MetadataManager) queryRunner.getMetadata();
}
Also used : MockConnectorFactory(com.facebook.presto.connector.MockConnectorFactory) MetadataManager(com.facebook.presto.metadata.MetadataManager) TableStatistics(com.facebook.presto.spi.statistics.TableStatistics) Assert.assertEquals(org.testng.Assert.assertEquals) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) IGNORE_STATS_CALCULATOR_FAILURES(com.facebook.presto.SystemSessionProperties.IGNORE_STATS_CALCULATOR_FAILURES) FAILED(com.facebook.presto.execution.QueryState.FAILED) TableHandle(com.facebook.presto.spi.TableHandle) BasicQueryInfo(com.facebook.presto.server.BasicQueryInfo) TpchQueryRunnerBuilder(com.facebook.presto.tests.tpch.TpchQueryRunnerBuilder) TransactionBuilder(com.facebook.presto.transaction.TransactionBuilder) AfterClass(org.testng.annotations.AfterClass) RUNNING(com.facebook.presto.execution.QueryState.RUNNING) ImmutableMap(com.google.common.collect.ImmutableMap) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) TestingSessionContext(com.facebook.presto.execution.TestingSessionContext) BeforeClass(org.testng.annotations.BeforeClass) Assert.fail(org.testng.Assert.fail) Constraint.alwaysTrue(com.facebook.presto.spi.Constraint.alwaysTrue) DispatchManager(com.facebook.presto.dispatcher.DispatchManager) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) ConnectorFactory(com.facebook.presto.spi.connector.ConnectorFactory) Plugin(com.facebook.presto.spi.Plugin) List(java.util.List) QueryId(com.facebook.presto.spi.QueryId) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) MockConnectorFactory(com.facebook.presto.connector.MockConnectorFactory) Plugin(com.facebook.presto.spi.Plugin) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MetadataManager (com.facebook.presto.metadata.MetadataManager)27 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)15 Test (org.testng.annotations.Test)15 MaterializedResult (com.facebook.presto.testing.MaterializedResult)11 Page (com.facebook.presto.common.Page)8 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)8 Type (com.facebook.presto.common.type.Type)7 RowExpression (com.facebook.presto.spi.relation.RowExpression)7 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)7 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)5 ArrayType (com.facebook.presto.common.type.ArrayType)5 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)5 RowType (com.facebook.presto.common.type.RowType)5 OperatorFactory (com.facebook.presto.operator.OperatorFactory)5 TestUnnesterUtil.buildExpectedPage (com.facebook.presto.operator.unnest.TestUnnesterUtil.buildExpectedPage)5 ConnectorId (com.facebook.presto.spi.ConnectorId)5 PageFunctionCompiler (com.facebook.presto.sql.gen.PageFunctionCompiler)5 Page (com.facebook.presto.spi.Page)4 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)4 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)4