Пример #1
0
  private void checkForSharedSourceCommand(AccessNode aNode) {
    // create a top level key to avoid the full command toString
    String modelName = aNode.getModelName();
    Command cmd = aNode.getCommand();

    // don't share full scans against internal sources, it's a waste of buffering
    if (CoreConstants.SYSTEM_MODEL.equals(modelName)
        || CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)
        || TempMetadataAdapter.TEMP_MODEL.getName().equals(modelName)) {
      if (!(cmd instanceof Query)) {
        return;
      }
      Query query = (Query) cmd;
      if (query.getOrderBy() == null && query.getCriteria() == null) {
        return;
      }
    }

    AccessNode other = sharedCommands.get(cmd);
    if (other == null) {
      sharedCommands.put(cmd, aNode);
    } else {
      if (other.info == null) {
        other.info = new RegisterRequestParameter.SharedAccessInfo();
        other.info.id = sharedId.getAndIncrement();
      }
      other.info.sharingCount++;
      aNode.info = other.info;
    }
  }
Пример #2
0
  private RelationalNode correctProjectionInternalTables(PlanNode node, AccessNode aNode)
      throws QueryMetadataException, TeiidComponentException {
    if (node.getGroups().size() != 1) {
      return aNode;
    }
    GroupSymbol group = node.getGroups().iterator().next();
    if (!CoreConstants.SYSTEM_MODEL.equals(
            metadata.getFullName(metadata.getModelID(group.getMetadataID())))
        && !CoreConstants.SYSTEM_ADMIN_MODEL.equals(
            metadata.getFullName(metadata.getModelID(group.getMetadataID())))) {
      return aNode;
    }
    List projectSymbols = (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS);
    List<ElementSymbol> acutalColumns = ResolverUtil.resolveElementsInGroup(group, metadata);
    if (projectSymbols.equals(acutalColumns)) {
      return aNode;
    }
    node.setProperty(NodeConstants.Info.OUTPUT_COLS, acutalColumns);
    if (node.getParent() != null && node.getParent().getType() == NodeConstants.Types.PROJECT) {
      // if the parent is already a project, just correcting the output cols is enough
      return aNode;
    }
    ProjectNode pnode = new ProjectNode(getID());

    pnode.setSelectSymbols(projectSymbols);
    aNode = (AccessNode) prepareToAdd(node, aNode);
    node.setProperty(NodeConstants.Info.OUTPUT_COLS, projectSymbols);
    pnode.addChild(aNode);
    return pnode;
  }
Пример #3
0
  TupleSource registerRequest(final CommandContext context, String modelName, final Command command)
      throws TeiidComponentException, TeiidProcessingException {
    final TempTableStore contextStore = context.getTempTableStore();
    if (command instanceof Query) {
      Query query = (Query) command;
      if (modelName != null && !modelName.equals(TempMetadataAdapter.TEMP_MODEL.getID())) {
        return null;
      }
      return registerQuery(context, contextStore, query);
    }
    if (command instanceof ProcedureContainer) {
      if (command instanceof StoredProcedure) {
        StoredProcedure proc = (StoredProcedure) command;
        if (CoreConstants.SYSTEM_ADMIN_MODEL.equals(modelName)) {
          TupleSource result = handleSystemProcedures(context, proc);
          if (result != null) {
            return result;
          }
        } else if (proc.getGroup().isGlobalTable()) {
          return handleCachedProcedure(context, proc);
        }
        return null; // it's not a stored procedure we want to handle
      }

      final GroupSymbol group = ((ProcedureContainer) command).getGroup();
      if (!modelName.equals(TempMetadataAdapter.TEMP_MODEL.getID()) || !group.isTempGroupSymbol()) {
        return null;
      }
      return new ProxyTupleSource() {

        @Override
        protected TupleSource createTupleSource()
            throws TeiidComponentException, TeiidProcessingException {
          final String groupKey = group.getNonCorrelationName();
          final TempTable table =
              contextStore.getOrCreateTempTable(
                  groupKey, command, bufferManager, true, true, context, group);
          if (command instanceof Insert) {
            Insert insert = (Insert) command;
            TupleSource ts = insert.getTupleSource();
            if (ts == null) {
              Evaluator eval =
                  new Evaluator(Collections.emptyMap(), TempTableDataManager.this, context);
              List<Object> values = new ArrayList<Object>(insert.getValues().size());
              for (Expression expr : (List<Expression>) insert.getValues()) {
                values.add(eval.evaluate(expr, null));
              }
              ts = new CollectionTupleSource(Arrays.asList(values).iterator());
            }
            return table.insert(ts, insert.getVariables(), true, context);
          }
          if (command instanceof Update) {
            final Update update = (Update) command;
            final Criteria crit = update.getCriteria();
            return table.update(crit, update.getChangeList());
          }
          if (command instanceof Delete) {
            final Delete delete = (Delete) command;
            final Criteria crit = delete.getCriteria();
            if (crit == null) {
              // TODO: we'll add a real truncate later
              int rows = table.truncate(false);
              return CollectionTupleSource.createUpdateCountTupleSource(rows);
            }
            return table.delete(crit);
          }
          throw new AssertionError("unknown command " + command); // $NON-NLS-1$
        }
      };
    }
    if (command instanceof Create) {
      Create create = (Create) command;
      String tempTableName = create.getTable().getName();
      if (contextStore.hasTempTable(tempTableName)) {
        throw new QueryProcessingException(
            QueryPlugin.Event.TEIID30229,
            QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30229, tempTableName));
      }
      if (create.getTableMetadata() != null) {
        contextStore.addForeignTempTable(tempTableName, create);
      } else {
        contextStore.addTempTable(tempTableName, create, bufferManager, true, context);
      }
      return CollectionTupleSource.createUpdateCountTupleSource(0);
    }
    if (command instanceof Drop) {
      String tempTableName = ((Drop) command).getTable().getName();
      contextStore.removeTempTableByName(tempTableName, context);
      return CollectionTupleSource.createUpdateCountTupleSource(0);
    }
    if (command instanceof AlterTempTable) {
      AlterTempTable att = (AlterTempTable) command;
      TempTable tt = contextStore.getTempTable(att.getTempTable());
      Assertion.isNotNull(tt, "Table doesn't exist"); // $NON-NLS-1$
      tt.setUpdatable(false);
      if (att.getIndexColumns() != null && tt.getRowCount() > 2 * tt.getTree().getPageSize(true)) {
        for (List<ElementSymbol> cols : att.getIndexColumns()) {
          tt.addIndex(cols, false);
        }
      }
      return CollectionTupleSource.createUpdateCountTupleSource(0);
    }
    return null;
  }