示例#1
0
  public static LocalQueryRunner createLocalQueryRunner(ExecutorService executor) {
    ConnectorSession session =
        new ConnectorSession(
            "user", "test", "default", "default", UTC_KEY, Locale.ENGLISH, null, null);
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(session, executor);

    // add tpch
    InMemoryNodeManager nodeManager = localQueryRunner.getNodeManager();
    localQueryRunner.createCatalog(
        "tpch", new TpchConnectorFactory(nodeManager, 1), ImmutableMap.<String, String>of());

    // add raptor
    RaptorConnectorFactory raptorConnectorFactory =
        createRaptorConnectorFactory(TPCH_CACHE_DIR, nodeManager);
    localQueryRunner.createCatalog(
        "default", raptorConnectorFactory, ImmutableMap.<String, String>of());

    MetadataManager metadata = localQueryRunner.getMetadata();
    if (!metadata
        .getTableHandle(session, new QualifiedTableName("default", "default", "orders"))
        .isPresent()) {
      localQueryRunner.execute("CREATE TABLE orders AS SELECT * FROM tpch.sf1.orders");
    }
    if (!metadata
        .getTableHandle(session, new QualifiedTableName("default", "default", "lineitem"))
        .isPresent()) {
      localQueryRunner.execute("CREATE TABLE lineitem AS SELECT * FROM tpch.sf1.lineitem");
    }
    return localQueryRunner;
  }
  @Test
  public void testSimpleMaps() throws Exception {
    MapType mapType = new MapType(DOUBLE, VARCHAR);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.VARCHAR));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, "a", 2.0, "b", 3.0, "c"),
        createDoublesBlock(1.0, 2.0, 3.0),
        createStringsBlock("a", "b", "c"));

    mapType = new MapType(DOUBLE, BIGINT);
    aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.BIGINT));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, 3L, 2.0, 2L, 3.0, 1L),
        createDoublesBlock(1.0, 2.0, 3.0),
        createLongsBlock(3L, 2L, 1L));

    mapType = new MapType(DOUBLE, BOOLEAN);
    aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.BOOLEAN));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, true, 2.0, false, 3.0, false),
        createDoublesBlock(1.0, 2.0, 3.0),
        createBooleansBlock(true, false, false));
  }
示例#3
0
  public OperatorFactory createTableScanOperator(
      Session session, int operatorId, String tableName, String... columnNames) {
    checkArgument(session.getCatalog().isPresent(), "catalog not set");
    checkArgument(session.getSchema().isPresent(), "schema not set");

    // look up the table
    QualifiedTableName qualifiedTableName =
        new QualifiedTableName(session.getCatalog().get(), session.getSchema().get(), tableName);
    TableHandle tableHandle = metadata.getTableHandle(session, qualifiedTableName).orElse(null);
    checkArgument(tableHandle != null, "Table %s does not exist", qualifiedTableName);

    // lookup the columns
    Map<String, ColumnHandle> allColumnHandles = metadata.getColumnHandles(session, tableHandle);
    ImmutableList.Builder<ColumnHandle> columnHandlesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Type> columnTypesBuilder = ImmutableList.builder();
    for (String columnName : columnNames) {
      ColumnHandle columnHandle = allColumnHandles.get(columnName);
      checkArgument(
          columnHandle != null, "Table %s does not have a column %s", tableName, columnName);
      columnHandlesBuilder.add(columnHandle);
      ColumnMetadata columnMetadata =
          metadata.getColumnMetadata(session, tableHandle, columnHandle);
      columnTypesBuilder.add(columnMetadata.getType());
    }
    List<ColumnHandle> columnHandles = columnHandlesBuilder.build();
    List<Type> columnTypes = columnTypesBuilder.build();

    // get the split for this table
    List<TableLayoutResult> layouts =
        metadata.getLayouts(session, tableHandle, Constraint.alwaysTrue(), Optional.empty());
    Split split = getLocalQuerySplit(layouts.get(0).getLayout().getHandle());

    return new OperatorFactory() {
      @Override
      public List<Type> getTypes() {
        return columnTypes;
      }

      @Override
      public Operator createOperator(DriverContext driverContext) {
        OperatorContext operatorContext =
            driverContext.addOperatorContext(operatorId, "BenchmarkSource");
        ConnectorPageSource pageSource =
            pageSourceManager.createPageSource(session, split, columnHandles);
        return new PageSourceOperator(pageSource, columnTypes, operatorContext);
      }

      @Override
      public void close() {}
    };
  }
  @Test
  public void testDoubleRowMap() throws Exception {
    RowType innerRowType =
        new RowType(ImmutableList.of(BIGINT, DOUBLE), Optional.of(ImmutableList.of("f1", "f2")));
    MapType mapType = new MapType(DOUBLE, innerRowType);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    innerRowType.getTypeSignature().toString()));

    BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerRowType.writeObject(builder, testRowBigintBigint(1L, 1.0));
    innerRowType.writeObject(builder, testRowBigintBigint(2L, 2.0));
    innerRowType.writeObject(builder, testRowBigintBigint(3L, 3.0));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            1.0,
            ImmutableList.of(1L, 1.0),
            2.0,
            ImmutableList.of(2L, 2.0),
            3.0,
            ImmutableList.of(3L, 3.0)),
        createDoublesBlock(1.0, 2.0, 3.0),
        builder.build());
  }
  @Test
  public void testArrayDoubleMap() throws Exception {
    ArrayType arrayType = new ArrayType(VARCHAR);
    MapType mapType = new MapType(arrayType, DOUBLE);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    arrayType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            ImmutableList.of("a", "b"), 1.0,
            ImmutableList.of("c", "d"), 2.0,
            ImmutableList.of("e", "f"), 3.0),
        createStringArraysBlock(
            ImmutableList.of(
                ImmutableList.of("a", "b"),
                ImmutableList.of("c", "d"),
                ImmutableList.of("e", "f"))),
        createDoublesBlock(1.0, 2.0, 3.0));
  }
  @Setup
  public void setup() {
    Random random = new Random();
    RowExpression[] arguments = new RowExpression[1 + inListCount];
    switch (type) {
      case StandardTypes.BIGINT:
        prestoType = BIGINT;
        for (int i = 1; i <= inListCount; i++) {
          arguments[i] = constant((long) random.nextInt(), BIGINT);
        }
        break;
      case StandardTypes.DOUBLE:
        prestoType = DOUBLE;
        for (int i = 1; i <= inListCount; i++) {
          arguments[i] = constant(random.nextDouble(), DOUBLE);
        }
        break;
      case StandardTypes.VARCHAR:
        prestoType = VARCHAR;
        for (int i = 1; i <= inListCount; i++) {
          arguments[i] = constant(Slices.utf8Slice(Long.toString(random.nextLong())), VARCHAR);
        }
        break;
      default:
        throw new IllegalStateException();
    }

    arguments[0] = field(0, prestoType);
    RowExpression project = field(0, prestoType);

    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(prestoType));
    for (int i = 0; i < 10_000; i++) {
      pageBuilder.declarePosition();

      switch (type) {
        case StandardTypes.BIGINT:
          BIGINT.writeLong(pageBuilder.getBlockBuilder(0), random.nextInt());
          break;
        case StandardTypes.DOUBLE:
          DOUBLE.writeDouble(pageBuilder.getBlockBuilder(0), random.nextDouble());
          break;
        case StandardTypes.VARCHAR:
          VARCHAR.writeSlice(
              pageBuilder.getBlockBuilder(0), Slices.utf8Slice(Long.toString(random.nextLong())));
          break;
      }
    }
    inputPage = pageBuilder.build();

    RowExpression filter =
        call(
            new Signature(IN, SCALAR, parseTypeSignature(StandardTypes.BOOLEAN)),
            BOOLEAN,
            arguments);

    processor =
        new ExpressionCompiler(MetadataManager.createTestMetadataManager())
            .compilePageProcessor(filter, ImmutableList.of(project))
            .get();
  }
  @Test
  public void testDoubleMapMap() throws Exception {
    MapType innerMapType = new MapType(VARCHAR, VARCHAR);
    MapType mapType = new MapType(DOUBLE, innerMapType);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    innerMapType.getTypeSignature().toString()));

    BlockBuilder builder = innerMapType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("a", "b")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("c", "d")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("e", "f")));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            1.0,
            ImmutableMap.of("a", "b"),
            2.0,
            ImmutableMap.of("c", "d"),
            3.0,
            ImmutableMap.of("e", "f")),
        createDoublesBlock(1.0, 2.0, 3.0),
        builder.build());
  }
示例#8
0
  public OperatorFactory createTableScanOperator(
      final int operatorId, String tableName, String... columnNames) {
    // look up the table
    TableHandle tableHandle =
        metadata
            .getTableHandle(
                session,
                new QualifiedTableName(session.getCatalog(), session.getSchema(), tableName))
            .orNull();
    checkArgument(tableHandle != null, "Table %s does not exist", tableName);

    // lookup the columns
    ImmutableList.Builder<ColumnHandle> columnHandlesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Type> columnTypesBuilder = ImmutableList.builder();
    for (String columnName : columnNames) {
      ColumnHandle columnHandle = metadata.getColumnHandle(tableHandle, columnName).orNull();
      checkArgument(
          columnHandle != null, "Table %s does not have a column %s", tableName, columnName);
      columnHandlesBuilder.add(columnHandle);
      ColumnMetadata columnMetadata = metadata.getColumnMetadata(tableHandle, columnHandle);
      columnTypesBuilder.add(columnMetadata.getType());
    }
    final List<ColumnHandle> columnHandles = columnHandlesBuilder.build();
    final List<Type> columnTypes = columnTypesBuilder.build();

    // get the split for this table
    final Split split = getLocalQuerySplit(tableHandle);

    return new OperatorFactory() {
      @Override
      public List<Type> getTypes() {
        return columnTypes;
      }

      @Override
      public Operator createOperator(DriverContext driverContext) {
        OperatorContext operatorContext =
            driverContext.addOperatorContext(operatorId, "BenchmarkSource");
        return dataStreamProvider.createNewDataStream(operatorContext, split, columnHandles);
      }

      @Override
      public void close() {}
    };
  }
示例#9
0
 @Test
 public void testEmpty() throws Exception {
   InternalAggregationFunction booleanAgg =
       metadata
           .getFunctionRegistry()
           .getAggregateFunctionImplementation(
               new Signature(
                   "checksum",
                   AGGREGATE,
                   parseTypeSignature(VARBINARY),
                   parseTypeSignature(BOOLEAN)));
   assertAggregation(booleanAgg, 1.0, null, createBooleansBlock());
 }
  @Test
  public void testDuplicateKeysValues() throws Exception {
    MapType mapType = new MapType(DOUBLE, VARCHAR);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.VARCHAR));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, "a"),
        createDoublesBlock(1.0, 1.0, 1.0),
        createStringsBlock("a", "b", "c"));

    mapType = new MapType(DOUBLE, BIGINT);
    aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.BIGINT));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, 99L, 2.0, 99L, 3.0, 99L),
        createDoublesBlock(1.0, 2.0, 3.0),
        createLongsBlock(99L, 99L, 99L));
  }
示例#11
0
 @Test
 public void testBoolean() throws Exception {
   InternalAggregationFunction booleanAgg =
       metadata
           .getFunctionRegistry()
           .getAggregateFunctionImplementation(
               new Signature(
                   "checksum",
                   AGGREGATE,
                   parseTypeSignature(VARBINARY),
                   parseTypeSignature(BOOLEAN)));
   Block block = createBooleansBlock(null, null, true, false, false);
   assertAggregation(booleanAgg, 1.0, expectedChecksum(BooleanType.BOOLEAN, block), block);
 }
示例#12
0
 @Test
 public void testLong() throws Exception {
   InternalAggregationFunction longAgg =
       metadata
           .getFunctionRegistry()
           .getAggregateFunctionImplementation(
               new Signature(
                   "checksum",
                   AGGREGATE,
                   parseTypeSignature(VARBINARY),
                   parseTypeSignature(BIGINT)));
   Block block = createLongsBlock(null, 1L, 2L, 100L, null, Long.MAX_VALUE, Long.MIN_VALUE);
   assertAggregation(longAgg, 1.0, expectedChecksum(BigintType.BIGINT, block), block);
 }
示例#13
0
 @Test
 public void testString() throws Exception {
   InternalAggregationFunction stringAgg =
       metadata
           .getFunctionRegistry()
           .getAggregateFunctionImplementation(
               new Signature(
                   "checksum",
                   AGGREGATE,
                   parseTypeSignature(VARBINARY),
                   parseTypeSignature(VARCHAR)));
   Block block = createStringsBlock("a", "a", null, "b", "c");
   assertAggregation(stringAgg, 1.0, expectedChecksum(VarcharType.VARCHAR, block), block);
 }
示例#14
0
 @Test
 public void testDouble() throws Exception {
   InternalAggregationFunction doubleAgg =
       metadata
           .getFunctionRegistry()
           .getAggregateFunctionImplementation(
               new Signature(
                   "checksum",
                   AGGREGATE,
                   parseTypeSignature(VARBINARY),
                   parseTypeSignature(DOUBLE)));
   Block block =
       createDoublesBlock(
           null, 2.0, null, 3.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN);
   assertAggregation(doubleAgg, 1.0, expectedChecksum(DoubleType.DOUBLE, block), block);
 }
示例#15
0
 @Test
 public void testArray() throws Exception {
   ArrayType arrayType = new ArrayType(BigintType.BIGINT);
   InternalAggregationFunction stringAgg =
       metadata
           .getFunctionRegistry()
           .getAggregateFunctionImplementation(
               new Signature(
                   "checksum",
                   AGGREGATE,
                   VarbinaryType.VARBINARY.getTypeSignature(),
                   arrayType.getTypeSignature()));
   Block block =
       createArrayBigintBlock(asList(null, asList(1L, 2L), asList(3L, 4L), asList(5L, 6L)));
   assertAggregation(stringAgg, 1.0, expectedChecksum(arrayType, block), block);
 }
  @Test
  public void testNull() throws Exception {
    InternalAggregationFunction doubleDouble =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    new MapType(DOUBLE, DOUBLE).getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.DOUBLE));
    assertAggregation(
        doubleDouble,
        1.0,
        ImmutableMap.of(1.0, 2.0),
        createDoublesBlock(1.0, null, null),
        createDoublesBlock(2.0, 3.0, 4.0));

    assertAggregation(
        doubleDouble,
        1.0,
        null,
        createDoublesBlock(null, null, null),
        createDoublesBlock(2.0, 3.0, 4.0));

    Map<Double, Double> expected = new LinkedHashMap<>();
    expected.put(1.0, null);
    expected.put(2.0, null);
    expected.put(3.0, null);
    assertAggregation(
        doubleDouble,
        1.0,
        expected,
        createDoublesBlock(1.0, 2.0, 3.0),
        createDoublesBlock(null, null, null));
  }
public class TestStartTransactionTask {
  private final MetadataManager metadata = MetadataManager.createTestMetadataManager();
  private final ExecutorService executor =
      newCachedThreadPool(daemonThreadsNamed("stage-executor-%s"));
  private final ScheduledExecutorService scheduledExecutor =
      newSingleThreadScheduledExecutor(daemonThreadsNamed("scheduled-executor-%s"));

  @AfterClass(alwaysRun = true)
  public void tearDown() throws Exception {
    executor.shutdownNow();
    scheduledExecutor.shutdownNow();
  }

  @Test
  public void testNonTransactionalClient() throws Exception {
    Session session = sessionBuilder().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);
    Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    try {
      try {
        new StartTransactionTask()
            .execute(
                new StartTransaction(ImmutableList.of()),
                transactionManager,
                metadata,
                new AllowAllAccessControl(),
                stateMachine)
            .join();
        Assert.fail();
      } catch (CompletionException e) {
        throw Throwables.propagate(e.getCause());
      }
    } catch (PrestoException e) {
      Assert.assertEquals(e.getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode());
    }
    Assert.assertTrue(transactionManager.getAllTransactionInfos().isEmpty());

    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertFalse(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
  }

  @Test
  public void testNestedTransaction() throws Exception {
    TransactionManager transactionManager = createTestTransactionManager();

    Session session =
        sessionBuilder()
            .setTransactionId(TransactionId.create())
            .setClientTransactionSupport()
            .build();
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);

    try {
      try {
        new StartTransactionTask()
            .execute(
                new StartTransaction(ImmutableList.of()),
                transactionManager,
                metadata,
                new AllowAllAccessControl(),
                stateMachine)
            .join();
        Assert.fail();
      } catch (CompletionException e) {
        throw Throwables.propagate(e.getCause());
      }
    } catch (PrestoException e) {
      Assert.assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode());
    }
    Assert.assertTrue(transactionManager.getAllTransactionInfos().isEmpty());

    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertFalse(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
  }

  @Test
  public void testStartTransaction() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);
    Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    new StartTransactionTask()
        .execute(
            new StartTransaction(ImmutableList.of()),
            transactionManager,
            metadata,
            new AllowAllAccessControl(),
            stateMachine)
        .join();
    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertTrue(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
    Assert.assertEquals(transactionManager.getAllTransactionInfos().size(), 1);

    TransactionInfo transactionInfo =
        transactionManager.getTransactionInfo(
            stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().get());
    Assert.assertFalse(transactionInfo.isAutoCommitContext());
  }

  @Test
  public void testStartTransactionExplicitModes() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);
    Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    new StartTransactionTask()
        .execute(
            new StartTransaction(
                ImmutableList.of(
                    new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))),
            transactionManager,
            metadata,
            new AllowAllAccessControl(),
            stateMachine)
        .join();
    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertTrue(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
    Assert.assertEquals(transactionManager.getAllTransactionInfos().size(), 1);

    TransactionInfo transactionInfo =
        transactionManager.getTransactionInfo(
            stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().get());
    Assert.assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE);
    Assert.assertTrue(transactionInfo.isReadOnly());
    Assert.assertFalse(transactionInfo.isAutoCommitContext());
  }

  @Test
  public void testStartTransactionTooManyIsolationLevels() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);
    Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    try {
      try {
        new StartTransactionTask()
            .execute(
                new StartTransaction(
                    ImmutableList.of(
                        new Isolation(Isolation.Level.READ_COMMITTED),
                        new Isolation(Isolation.Level.READ_COMMITTED))),
                transactionManager,
                metadata,
                new AllowAllAccessControl(),
                stateMachine)
            .join();
        Assert.fail();
      } catch (CompletionException e) {
        throw Throwables.propagate(e.getCause());
      }
    } catch (SemanticException e) {
      Assert.assertEquals(e.getCode(), INVALID_TRANSACTION_MODE);
    }
    Assert.assertTrue(transactionManager.getAllTransactionInfos().isEmpty());

    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertFalse(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
  }

  @Test
  public void testStartTransactionTooManyAccessModes() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);
    Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    try {
      try {
        new StartTransactionTask()
            .execute(
                new StartTransaction(
                    ImmutableList.of(
                        new TransactionAccessMode(true), new TransactionAccessMode(true))),
                transactionManager,
                metadata,
                new AllowAllAccessControl(),
                stateMachine)
            .join();
        Assert.fail();
      } catch (CompletionException e) {
        throw Throwables.propagate(e.getCause());
      }
    } catch (SemanticException e) {
      Assert.assertEquals(e.getCode(), INVALID_TRANSACTION_MODE);
    }
    Assert.assertTrue(transactionManager.getAllTransactionInfos().isEmpty());

    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertFalse(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
  }

  @Test
  public void testStartTransactionIdleExpiration() throws Exception {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager =
        TransactionManager.create(
            new TransactionManagerConfig()
                .setIdleTimeout(new Duration(1, TimeUnit.MICROSECONDS)) // Fast idle timeout
                .setIdleCheckInterval(new Duration(10, TimeUnit.MILLISECONDS)),
            scheduledExecutor,
            executor);
    QueryStateMachine stateMachine =
        QueryStateMachine.begin(
            new QueryId("query"),
            "START TRANSACTION",
            session,
            URI.create("fake://uri"),
            true,
            transactionManager,
            executor);
    Assert.assertFalse(stateMachine.getSession().getTransactionId().isPresent());

    new StartTransactionTask()
        .execute(
            new StartTransaction(ImmutableList.of()),
            transactionManager,
            metadata,
            new AllowAllAccessControl(),
            stateMachine)
        .join();
    Assert.assertFalse(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
    Assert.assertTrue(
        stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());

    long start = System.nanoTime();
    while (!transactionManager.getAllTransactionInfos().isEmpty()) {
      if (Duration.nanosSince(start).toMillis() > 10_000) {
        Assert.fail("Transaction did not expire in the allotted time");
      }
      TimeUnit.MILLISECONDS.sleep(10);
    }
  }

  private static SessionBuilder sessionBuilder() {
    return testSessionBuilder().setCatalog("tpch").setSchema(TINY_SCHEMA_NAME);
  }
}
public class TestMapAggAggregation {
  private static final MetadataManager metadata = MetadataManager.createTestMetadataManager();

  @Test
  public void testDuplicateKeysValues() throws Exception {
    MapType mapType = new MapType(DOUBLE, VARCHAR);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.VARCHAR));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, "a"),
        createDoublesBlock(1.0, 1.0, 1.0),
        createStringsBlock("a", "b", "c"));

    mapType = new MapType(DOUBLE, BIGINT);
    aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.BIGINT));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, 99L, 2.0, 99L, 3.0, 99L),
        createDoublesBlock(1.0, 2.0, 3.0),
        createLongsBlock(99L, 99L, 99L));
  }

  @Test
  public void testSimpleMaps() throws Exception {
    MapType mapType = new MapType(DOUBLE, VARCHAR);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.VARCHAR));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, "a", 2.0, "b", 3.0, "c"),
        createDoublesBlock(1.0, 2.0, 3.0),
        createStringsBlock("a", "b", "c"));

    mapType = new MapType(DOUBLE, BIGINT);
    aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.BIGINT));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, 3L, 2.0, 2L, 3.0, 1L),
        createDoublesBlock(1.0, 2.0, 3.0),
        createLongsBlock(3L, 2L, 1L));

    mapType = new MapType(DOUBLE, BOOLEAN);
    aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.BOOLEAN));
    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(1.0, true, 2.0, false, 3.0, false),
        createDoublesBlock(1.0, 2.0, 3.0),
        createBooleansBlock(true, false, false));
  }

  @Test
  public void testNull() throws Exception {
    InternalAggregationFunction doubleDouble =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    new MapType(DOUBLE, DOUBLE).getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    StandardTypes.DOUBLE));
    assertAggregation(
        doubleDouble,
        1.0,
        ImmutableMap.of(1.0, 2.0),
        createDoublesBlock(1.0, null, null),
        createDoublesBlock(2.0, 3.0, 4.0));

    assertAggregation(
        doubleDouble,
        1.0,
        null,
        createDoublesBlock(null, null, null),
        createDoublesBlock(2.0, 3.0, 4.0));

    Map<Double, Double> expected = new LinkedHashMap<>();
    expected.put(1.0, null);
    expected.put(2.0, null);
    expected.put(3.0, null);
    assertAggregation(
        doubleDouble,
        1.0,
        expected,
        createDoublesBlock(1.0, 2.0, 3.0),
        createDoublesBlock(null, null, null));
  }

  @Test
  public void testDoubleArrayMap() throws Exception {
    ArrayType arrayType = new ArrayType(VARCHAR);
    MapType mapType = new MapType(DOUBLE, arrayType);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    arrayType.getTypeSignature().toString()));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            1.0,
            ImmutableList.of("a", "b"),
            2.0,
            ImmutableList.of("c", "d"),
            3.0,
            ImmutableList.of("e", "f")),
        createDoublesBlock(1.0, 2.0, 3.0),
        createStringArraysBlock(
            ImmutableList.of(
                ImmutableList.of("a", "b"),
                ImmutableList.of("c", "d"),
                ImmutableList.of("e", "f"))));
  }

  @Test
  public void testDoubleMapMap() throws Exception {
    MapType innerMapType = new MapType(VARCHAR, VARCHAR);
    MapType mapType = new MapType(DOUBLE, innerMapType);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    innerMapType.getTypeSignature().toString()));

    BlockBuilder builder = innerMapType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("a", "b")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("c", "d")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("e", "f")));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            1.0,
            ImmutableMap.of("a", "b"),
            2.0,
            ImmutableMap.of("c", "d"),
            3.0,
            ImmutableMap.of("e", "f")),
        createDoublesBlock(1.0, 2.0, 3.0),
        builder.build());
  }

  @Test
  public void testDoubleRowMap() throws Exception {
    RowType innerRowType =
        new RowType(ImmutableList.of(BIGINT, DOUBLE), Optional.of(ImmutableList.of("f1", "f2")));
    MapType mapType = new MapType(DOUBLE, innerRowType);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE,
                    innerRowType.getTypeSignature().toString()));

    BlockBuilder builder = innerRowType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerRowType.writeObject(builder, testRowBigintBigint(1L, 1.0));
    innerRowType.writeObject(builder, testRowBigintBigint(2L, 2.0));
    innerRowType.writeObject(builder, testRowBigintBigint(3L, 3.0));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            1.0,
            ImmutableList.of(1L, 1.0),
            2.0,
            ImmutableList.of(2L, 2.0),
            3.0,
            ImmutableList.of(3L, 3.0)),
        createDoublesBlock(1.0, 2.0, 3.0),
        builder.build());
  }

  @Test
  public void testArrayDoubleMap() throws Exception {
    ArrayType arrayType = new ArrayType(VARCHAR);
    MapType mapType = new MapType(arrayType, DOUBLE);
    InternalAggregationFunction aggFunc =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    NAME,
                    AGGREGATE,
                    mapType.getTypeSignature().toString(),
                    arrayType.getTypeSignature().toString(),
                    StandardTypes.DOUBLE));

    assertAggregation(
        aggFunc,
        1.0,
        ImmutableMap.of(
            ImmutableList.of("a", "b"), 1.0,
            ImmutableList.of("c", "d"), 2.0,
            ImmutableList.of("e", "f"), 3.0),
        createStringArraysBlock(
            ImmutableList.of(
                ImmutableList.of("a", "b"),
                ImmutableList.of("c", "d"),
                ImmutableList.of("e", "f"))),
        createDoublesBlock(1.0, 2.0, 3.0));
  }
}
示例#19
0
  public LocalQueryRunner(Session defaultSession) {
    requireNonNull(defaultSession, "defaultSession is null");
    this.executor = newCachedThreadPool(daemonThreadsNamed("local-query-runner-%s"));

    this.sqlParser = new SqlParser();
    this.nodeManager = new InMemoryNodeManager();
    this.typeRegistry = new TypeRegistry();
    this.indexManager = new IndexManager();
    this.pageSinkManager = new PageSinkManager();

    this.splitManager = new SplitManager();
    this.blockEncodingSerde = new BlockEncodingManager(typeRegistry);
    this.metadata =
        new MetadataManager(
            new FeaturesConfig().setExperimentalSyntaxEnabled(true),
            typeRegistry,
            splitManager,
            blockEncodingSerde,
            new SessionPropertyManager(),
            new TablePropertyManager());
    this.accessControl = new TestingAccessControlManager();
    this.pageSourceManager = new PageSourceManager();

    this.compiler = new ExpressionCompiler(metadata);

    this.connectorManager =
        new ConnectorManager(
            metadata,
            accessControl,
            splitManager,
            pageSourceManager,
            indexManager,
            pageSinkManager,
            new HandleResolver(),
            ImmutableMap.<String, ConnectorFactory>of(),
            nodeManager);

    Connector systemConnector =
        new SystemConnector(
            nodeManager,
            ImmutableSet.of(
                new NodeSystemTable(nodeManager),
                new CatalogSystemTable(metadata),
                new TablePropertiesSystemTable(metadata)));

    connectorManager.createConnection(SystemConnector.NAME, systemConnector);

    // rewrite session to use managed SessionPropertyMetadata
    this.defaultSession =
        new Session(
            defaultSession.getIdentity(),
            defaultSession.getSource(),
            defaultSession.getCatalog(),
            defaultSession.getSchema(),
            defaultSession.getTimeZoneKey(),
            defaultSession.getLocale(),
            defaultSession.getRemoteUserAddress(),
            defaultSession.getUserAgent(),
            defaultSession.getStartTime(),
            defaultSession.getSystemProperties(),
            defaultSession.getCatalogProperties(),
            metadata.getSessionPropertyManager());

    dataDefinitionTask =
        ImmutableMap.<Class<? extends Statement>, DataDefinitionTask<?>>builder()
            .put(CreateTable.class, new CreateTableTask())
            .put(
                CreateView.class,
                new CreateViewTask(
                    jsonCodec(ViewDefinition.class),
                    sqlParser,
                    accessControl,
                    new FeaturesConfig()))
            .put(DropTable.class, new DropTableTask())
            .put(DropView.class, new DropViewTask())
            .put(RenameColumn.class, new RenameColumnTask())
            .put(RenameTable.class, new RenameTableTask())
            .put(ResetSession.class, new ResetSessionTask())
            .put(SetSession.class, new SetSessionTask())
            .build();
  }
示例#20
0
public class TestChecksumAggregation {
  private static final MetadataManager metadata = MetadataManager.createTestMetadataManager();

  @Test
  public void testEmpty() throws Exception {
    InternalAggregationFunction booleanAgg =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    "checksum",
                    AGGREGATE,
                    parseTypeSignature(VARBINARY),
                    parseTypeSignature(BOOLEAN)));
    assertAggregation(booleanAgg, 1.0, null, createBooleansBlock());
  }

  @Test
  public void testBoolean() throws Exception {
    InternalAggregationFunction booleanAgg =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    "checksum",
                    AGGREGATE,
                    parseTypeSignature(VARBINARY),
                    parseTypeSignature(BOOLEAN)));
    Block block = createBooleansBlock(null, null, true, false, false);
    assertAggregation(booleanAgg, 1.0, expectedChecksum(BooleanType.BOOLEAN, block), block);
  }

  @Test
  public void testLong() throws Exception {
    InternalAggregationFunction longAgg =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    "checksum",
                    AGGREGATE,
                    parseTypeSignature(VARBINARY),
                    parseTypeSignature(BIGINT)));
    Block block = createLongsBlock(null, 1L, 2L, 100L, null, Long.MAX_VALUE, Long.MIN_VALUE);
    assertAggregation(longAgg, 1.0, expectedChecksum(BigintType.BIGINT, block), block);
  }

  @Test
  public void testDouble() throws Exception {
    InternalAggregationFunction doubleAgg =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    "checksum",
                    AGGREGATE,
                    parseTypeSignature(VARBINARY),
                    parseTypeSignature(DOUBLE)));
    Block block =
        createDoublesBlock(
            null, 2.0, null, 3.0, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, Double.NaN);
    assertAggregation(doubleAgg, 1.0, expectedChecksum(DoubleType.DOUBLE, block), block);
  }

  @Test
  public void testString() throws Exception {
    InternalAggregationFunction stringAgg =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    "checksum",
                    AGGREGATE,
                    parseTypeSignature(VARBINARY),
                    parseTypeSignature(VARCHAR)));
    Block block = createStringsBlock("a", "a", null, "b", "c");
    assertAggregation(stringAgg, 1.0, expectedChecksum(VarcharType.VARCHAR, block), block);
  }

  @Test
  public void testArray() throws Exception {
    ArrayType arrayType = new ArrayType(BigintType.BIGINT);
    InternalAggregationFunction stringAgg =
        metadata
            .getFunctionRegistry()
            .getAggregateFunctionImplementation(
                new Signature(
                    "checksum",
                    AGGREGATE,
                    VarbinaryType.VARBINARY.getTypeSignature(),
                    arrayType.getTypeSignature()));
    Block block =
        createArrayBigintBlock(asList(null, asList(1L, 2L), asList(3L, 4L), asList(5L, 6L)));
    assertAggregation(stringAgg, 1.0, expectedChecksum(arrayType, block), block);
  }

  private static SqlVarbinary expectedChecksum(Type type, Block block) {
    long result = 0;
    for (int i = 0; i < block.getPositionCount(); i++) {
      if (block.isNull(i)) {
        result += PRIME64;
      } else {
        result += type.hash(block, i) * PRIME64;
      }
    }
    return new SqlVarbinary(wrappedLongArray(result).getBytes());
  }
}
    @Setup
    public void setup() {
      MetadataManager metadata = MetadataManager.createTestMetadataManager();
      ExpressionCompiler compiler = new ExpressionCompiler(metadata);

      List<String> keys;
      switch (mapSize) {
        case 1:
          keys = ImmutableList.of("do_not_use");
          break;
        case 13:
          keys =
              ImmutableList.of(
                  "is_inverted",
                  "device_model",
                  "country",
                  "carrier_id",
                  "network_type",
                  "os_version",
                  "device_brand",
                  "device_type",
                  "interface",
                  "device_os",
                  "app_version",
                  "device_type_class",
                  "browser");
          break;
        default:
          throw new UnsupportedOperationException();
      }
      verify(keys.size() == mapSize);

      MapType mapType;
      Block valueBlock;
      switch (name) {
        case "fix-width":
          mapType = new MapType(createUnboundedVarcharType(), DOUBLE);
          valueBlock = createFixWidthValueBlock(POSITIONS, mapSize);
          break;
        case "var-width":
          mapType = new MapType(createUnboundedVarcharType(), createUnboundedVarcharType());
          valueBlock = createVarWidthValueBlock(POSITIONS, mapSize);
          break;
        case "dictionary":
          mapType = new MapType(createUnboundedVarcharType(), createUnboundedVarcharType());
          valueBlock = createDictionaryValueBlock(POSITIONS, mapSize);
          break;
        default:
          throw new UnsupportedOperationException();
      }

      Block keyBlock = createKeyBlock(POSITIONS, keys);
      Block block = createMapBlock(POSITIONS, keyBlock, valueBlock);

      ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();

      Signature signature =
          new Signature(
              "$operator$" + SUBSCRIPT.name(),
              FunctionKind.SCALAR,
              mapType.getValueType().getTypeSignature(),
              mapType.getTypeSignature(),
              mapType.getKeyType().getTypeSignature());
      for (int i = 0; i < mapSize; i++) {
        projectionsBuilder.add(
            new CallExpression(
                signature,
                mapType.getValueType(),
                ImmutableList.of(
                    new InputReferenceExpression(0, mapType),
                    new ConstantExpression(utf8Slice(keys.get(i)), createUnboundedVarcharType()))));
      }

      ImmutableList<RowExpression> projections = projectionsBuilder.build();
      pageProcessor =
          compiler
              .compilePageProcessor(new ConstantExpression(true, BooleanType.BOOLEAN), projections)
              .get();
      pageBuilder =
          new PageBuilder(
              projections.stream().map(RowExpression::getType).collect(Collectors.toList()));
      page = new Page(block);
    }
示例#22
0
  private void addConnector(String catalogName, String connectorId, Connector connector) {
    ConnectorMetadata connectorMetadata = connector.getMetadata();
    checkState(connectorMetadata != null, "Connector %s can not provide metadata", connectorId);

    ConnectorSplitManager connectorSplitManager = connector.getSplitManager();
    checkState(
        connectorSplitManager != null, "Connector %s does not have a split manager", connectorId);

    ConnectorPageSourceProvider connectorPageSourceProvider = null;
    try {
      connectorPageSourceProvider = connector.getPageSourceProvider();
      checkNotNull(
          connectorPageSourceProvider,
          "Connector %s returned a null page source provider",
          connectorId);
    } catch (UnsupportedOperationException ignored) {
    }

    if (connectorPageSourceProvider == null) {
      ConnectorRecordSetProvider connectorRecordSetProvider = null;
      try {
        connectorRecordSetProvider = connector.getRecordSetProvider();
        checkNotNull(
            connectorRecordSetProvider,
            "Connector %s returned a null record set provider",
            connectorId);
      } catch (UnsupportedOperationException ignored) {
      }
      checkState(
          connectorRecordSetProvider != null,
          "Connector %s has neither a PageSource or RecordSet provider",
          connectorId);
      connectorPageSourceProvider = new RecordPageSourceProvider(connectorRecordSetProvider);
    }

    ConnectorHandleResolver connectorHandleResolver = connector.getHandleResolver();
    checkNotNull(
        connectorHandleResolver, "Connector %s does not have a handle resolver", connectorId);

    ConnectorPageSinkProvider connectorPageSinkProvider = null;
    try {
      connectorPageSinkProvider = connector.getPageSinkProvider();
      checkNotNull(
          connectorPageSinkProvider,
          "Connector %s returned a null page sink provider",
          connectorId);
    } catch (UnsupportedOperationException ignored) {
    }

    if (connectorPageSinkProvider == null) {
      ConnectorRecordSinkProvider connectorRecordSinkProvider = null;
      try {
        connectorRecordSinkProvider = connector.getRecordSinkProvider();
        checkNotNull(
            connectorRecordSinkProvider,
            "Connector %s returned a null record sink provider",
            connectorId);
        connectorPageSinkProvider = new RecordPageSinkProvider(connectorRecordSinkProvider);
      } catch (UnsupportedOperationException ignored) {
      }
    }

    ConnectorIndexResolver indexResolver = null;
    try {
      indexResolver = connector.getIndexResolver();
      checkNotNull(indexResolver, "Connector %s returned a null index resolver", connectorId);
    } catch (UnsupportedOperationException ignored) {
    }

    // IMPORTANT: all the instances need to be fetched from the connector *before* we add them to
    // the corresponding managers.
    // Otherwise, a broken connector would leave the managers in an inconsistent state with respect
    // to each other

    metadataManager.addConnectorMetadata(connectorId, catalogName, connectorMetadata);

    metadataManager.addInformationSchemaMetadata(
        makeInformationSchemaConnectorId(connectorId),
        catalogName,
        new InformationSchemaMetadata(catalogName));
    splitManager.addConnectorSplitManager(
        makeInformationSchemaConnectorId(connectorId),
        new InformationSchemaSplitManager(nodeManager));
    pageSourceManager.addConnectorPageSourceProvider(
        makeInformationSchemaConnectorId(connectorId),
        new InformationSchemaPageSourceProvider(metadataManager, splitManager));

    splitManager.addConnectorSplitManager(connectorId, connectorSplitManager);
    handleResolver.addHandleResolver(connectorId, connectorHandleResolver);
    pageSourceManager.addConnectorPageSourceProvider(connectorId, connectorPageSourceProvider);

    if (connectorPageSinkProvider != null) {
      pageSinkManager.addConnectorPageSinkProvider(connectorId, connectorPageSinkProvider);
    }

    if (indexResolver != null) {
      indexManager.addIndexResolver(connectorId, indexResolver);
    }
  }
 @Override
 public InternalAggregationFunction getFunction() {
   return metadata
       .resolveFunction(new QualifiedName("var_pop"), ImmutableList.<Type>of(BIGINT), false)
       .getAggregationFunction();
 }
示例#24
0
  @BeforeMethod
  public void setUp() throws Exception {
    DualMetadata dualMetadata = new DualMetadata();
    TableHandle tableHandle =
        dualMetadata.getTableHandle(new SchemaTableName("default", DualMetadata.NAME));
    assertNotNull(tableHandle, "tableHandle is null");

    ColumnHandle columnHandle = dualMetadata.getColumnHandle(tableHandle, DualMetadata.COLUMN_NAME);
    assertNotNull(columnHandle, "columnHandle is null");
    Symbol symbol = new Symbol(DualMetadata.COLUMN_NAME);

    MetadataManager metadata = new MetadataManager(new FeaturesConfig());
    metadata.addInternalSchemaMetadata(MetadataManager.INTERNAL_CONNECTOR_ID, dualMetadata);

    DualSplitManager dualSplitManager = new DualSplitManager(new InMemoryNodeManager());
    PartitionResult partitionResult =
        dualSplitManager.getPartitions(tableHandle, TupleDomain.all());

    SplitSource splitSource =
        dualSplitManager.getPartitionSplits(tableHandle, partitionResult.getPartitions());
    split = Iterables.getOnlyElement(splitSource.getNextBatch(1));
    assertTrue(splitSource.isFinished());

    LocalExecutionPlanner planner =
        new LocalExecutionPlanner(
            new NodeInfo("test"),
            metadata,
            new DataStreamManager(new DualDataStreamProvider()),
            new MockLocalStorageManager(new File("target/temp")),
            new RecordSinkManager(),
            new MockExchangeClientSupplier(),
            new ExpressionCompiler(metadata));

    taskExecutor = new TaskExecutor(8);
    taskExecutor.start();

    tableScanNodeId = new PlanNodeId("tableScan");
    PlanFragment testFragment =
        new PlanFragment(
            new PlanFragmentId("fragment"),
            new TableScanNode(
                tableScanNodeId,
                tableHandle,
                ImmutableList.of(symbol),
                ImmutableMap.of(symbol, columnHandle),
                null,
                Optional.<GeneratedPartitions>absent()),
            ImmutableMap.of(symbol, Type.VARCHAR),
            PlanDistribution.SOURCE,
            tableScanNodeId,
            OutputPartitioning.NONE,
            ImmutableList.<Symbol>of());

    TaskId taskId = new TaskId("query", "stage", "task");
    Session session = new Session("user", "test", "default", "default", "test", "test");

    taskNotificationExecutor = Executors.newCachedThreadPool(threadsNamed("task-notification-%d"));

    outputBuffers = OutputBuffers.INITIAL_EMPTY_OUTPUT_BUFFERS;

    taskExecution =
        SqlTaskExecution.createSqlTaskExecution(
            session,
            taskId,
            URI.create("fake://task/" + taskId),
            testFragment,
            ImmutableList.<TaskSource>of(),
            outputBuffers,
            planner,
            new DataSize(32, Unit.MEGABYTE),
            taskExecutor,
            taskNotificationExecutor,
            new DataSize(256, Unit.MEGABYTE),
            new DataSize(8, Unit.MEGABYTE),
            new QueryMonitor(
                new ObjectMapperProvider().get(), new NullEventClient(), new NodeInfo("test")),
            false);
  }