示例#1
0
  /**
   * Return reference to default schema instance in a schema tree. Each {@link
   * org.apache.calcite.schema.SchemaPlus} instance can refer to its parent and its children. From
   * the returned reference to default schema instance, clients can traverse the entire schema tree
   * and know the default schema where to look up the tables first.
   *
   * @return Reference to default schema instance in a schema tree.
   */
  public SchemaPlus getNewDefaultSchema() {
    final SchemaPlus rootSchema = getRootSchema();
    final SchemaPlus defaultSchema = session.getDefaultSchema(rootSchema);
    if (defaultSchema == null) {
      return rootSchema;
    }

    return defaultSchema;
  }
 public Builder withUserProperties(UserProperties properties) {
   userSession.properties = Maps.newHashMap();
   if (properties != null) {
     for (int i = 0; i < properties.getPropertiesCount(); i++) {
       Property prop = properties.getProperties(i);
       userSession.properties.put(prop.getKey(), prop.getValue());
     }
   }
   return this;
 }
示例#3
0
 void setUser(UserToBitHandshake inbound) throws IOException {
   session =
       UserSession.Builder.newBuilder()
           .withCredentials(inbound.getCredentials())
           .withOptionManager(worker.getSystemOptions())
           .withUserProperties(inbound.getProperties())
           .setSupportComplexTypes(inbound.getSupportComplexTypes())
           .build();
   final String targetName = session.getTargetUserName();
   if (impersonationManager != null && targetName != null) {
     impersonationManager.replaceUserOnSession(targetName, session);
   }
 }
  public static void setControls(final UserSession session, final String controls) {
    validateControlsString(controls);
    final OptionValue opValue =
        OptionValue.createString(
            OptionValue.OptionType.SESSION, DRILLBIT_CONTROL_INJECTIONS, controls);

    final OptionManager options = session.getOptions();
    try {
      DRILLBIT_CONTROLS_VALIDATOR.validate(opValue, null);
      options.setOption(opValue);
    } catch (final Exception e) {
      fail("Could not set controls options: " + e.getMessage());
    }
    incrementer.increment(session); // to simulate that a query completed
  }
示例#5
0
  public QueryContext(
      final UserSession session, final DrillbitContext drillbitContext, QueryId queryId) {
    this.drillbitContext = drillbitContext;
    this.session = session;
    queryOptions = new QueryOptionManager(session.getOptions());
    executionControls = new ExecutionControls(queryOptions, drillbitContext.getEndpoint());
    plannerSettings = new PlannerSettings(queryOptions, getFunctionRegistry());
    plannerSettings.setNumEndPoints(drillbitContext.getBits().size());
    table = new DrillOperatorTable(getFunctionRegistry(), drillbitContext.getOptionManager());

    queryContextInfo = Utilities.createQueryContextInfo(session.getDefaultSchemaName());
    contextInformation = new ContextInformation(session.getCredentials(), queryContextInfo);

    allocator =
        drillbitContext
            .getAllocator()
            .newChildAllocator(
                "query:" + QueryIdHelper.getQueryId(queryId),
                PlannerSettings.getInitialPlanningMemorySize(),
                plannerSettings.getPlanningMemoryLimit());
    bufferManager = new BufferManagerImpl(this.allocator);
    viewExpansionContext = new ViewExpansionContext(this);
    schemaTreeProvider = new SchemaTreeProvider(drillbitContext);
  }
    @Override
    public CreateTableEntry createNewTable(String tableName) {
      String storage =
          session.getOptions().getOption(ExecConstants.OUTPUT_FORMAT_OPTION).string_val;
      FormatPlugin formatPlugin = plugin.getFormatPlugin(storage);
      if (formatPlugin == null)
        throw new UnsupportedOperationException(
            String.format(
                "Unsupported format '%s' in workspace '%s'",
                config.getStorageFormat(), Joiner.on(".").join(getSchemaPath())));

      return new FileSystemCreateTableEntry(
          (FileSystemConfig) plugin.getConfig(),
          formatPlugin,
          config.getLocation() + Path.SEPARATOR + tableName);
    }
 public Builder setSupportComplexTypes(boolean supportComplexTypes) {
   userSession.supportComplexTypes = supportComplexTypes;
   return this;
 }
 public Builder withOptionManager(OptionManager systemOptions) {
   userSession.sessionOptions = new SessionOptionManager(systemOptions);
   return this;
 }
 public Builder withCredentials(UserCredentials credentials) {
   userSession.credentials = credentials;
   return this;
 }
示例#10
0
 @Override
 public void increment(final UserSession session) {
   session.incrementQueryCount(this);
 }
示例#11
0
 /**
  * Get the user name of the user who issued the query that is managed by this QueryContext.
  *
  * @return
  */
 public String getQueryUserName() {
   return session.getCredentials().getUserName();
 }
示例#12
0
  protected QueryWorkUnit generateWorkUnit(
      OptionList options,
      DrillbitEndpoint foremanNode,
      QueryId queryId,
      PhysicalPlanReader reader,
      Fragment rootNode,
      PlanningSet planningSet,
      UserSession session,
      QueryContextInformation queryContextInfo)
      throws ExecutionSetupException {
    List<PlanFragment> fragments = Lists.newArrayList();

    PlanFragment rootFragment = null;
    FragmentRoot rootOperator = null;

    // now we generate all the individual plan fragments and associated assignments. Note, we need
    // all endpoints
    // assigned before we can materialize, so we start a new loop here rather than utilizing the
    // previous one.
    for (Wrapper wrapper : planningSet) {
      Fragment node = wrapper.getNode();
      final PhysicalOperator physicalOperatorRoot = node.getRoot();
      boolean isRootNode = rootNode == node;

      if (isRootNode && wrapper.getWidth() != 1) {
        throw new ForemanSetupException(
            String.format(
                "Failure while trying to setup fragment. "
                    + "The root fragment must always have parallelization one. In the current case, the width was set to %d.",
                wrapper.getWidth()));
      }
      // a fragment is self driven if it doesn't rely on any other exchanges.
      boolean isLeafFragment = node.getReceivingExchangePairs().size() == 0;

      // Create a minorFragment for each major fragment.
      for (int minorFragmentId = 0; minorFragmentId < wrapper.getWidth(); minorFragmentId++) {
        IndexedFragmentNode iNode = new IndexedFragmentNode(minorFragmentId, wrapper);
        wrapper.resetAllocation();
        PhysicalOperator op = physicalOperatorRoot.accept(Materializer.INSTANCE, iNode);
        Preconditions.checkArgument(op instanceof FragmentRoot);
        FragmentRoot root = (FragmentRoot) op;

        // get plan as JSON
        String plan;
        String optionsData;
        try {
          plan = reader.writeJson(root);
          optionsData = reader.writeJson(options);
        } catch (JsonProcessingException e) {
          throw new ForemanSetupException("Failure while trying to convert fragment into json.", e);
        }

        FragmentHandle handle =
            FragmentHandle //
                .newBuilder() //
                .setMajorFragmentId(wrapper.getMajorFragmentId()) //
                .setMinorFragmentId(minorFragmentId) //
                .setQueryId(queryId) //
                .build();

        PlanFragment fragment =
            PlanFragment.newBuilder() //
                .setForeman(foremanNode) //
                .setFragmentJson(plan) //
                .setHandle(handle) //
                .setAssignment(wrapper.getAssignedEndpoint(minorFragmentId)) //
                .setLeafFragment(isLeafFragment) //
                .setContext(queryContextInfo)
                .setMemInitial(wrapper.getInitialAllocation()) //
                .setMemMax(wrapper.getMaxAllocation())
                .setOptionsJson(optionsData)
                .setCredentials(session.getCredentials())
                .addAllCollector(CountRequiredFragments.getCollectors(root))
                .build();

        if (isRootNode) {
          logger.debug("Root fragment:\n {}", DrillStringUtils.unescapeJava(fragment.toString()));
          rootFragment = fragment;
          rootOperator = root;
        } else {
          logger.debug("Remote fragment:\n {}", DrillStringUtils.unescapeJava(fragment.toString()));
          fragments.add(fragment);
        }
      }
    }

    return new QueryWorkUnit(rootOperator, rootFragment, fragments);
  }