Ejemplo n.º 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;
  }
Ejemplo n.º 2
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() {}
    };
  }
Ejemplo n.º 3
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() {}
    };
  }