Ejemplo n.º 1
0
 @Test(expected = TeiidRuntimeException.class)
 public void testKeepAliases1() throws Exception {
   String sql =
       "select g_1.intkey as a, g_1.stringkey as b from BQT1.SmallA g_1, BQT1.SmallB ORDER BY a, b"; //$NON-NLS-1$
   String expected =
       "SELECT g.IntKey AS c_0, g.StringKey AS c_1 FROM BQT1.SmallA AS g ORDER BY c_0, c_1"; //$NON-NLS-1$
   AliasGenerator av = new AliasGenerator(true, false);
   Map<String, String> aliasMap = new HashMap<String, String>();
   aliasMap.put("g_1", "g_1");
   av.setAliasMapping(aliasMap);
   helpTest(sql, expected, RealMetadataFactory.exampleBQTCached(), av);
 }
Ejemplo n.º 2
0
 private Command aliasCommand(AccessNode aNode, Command command, Object modelID)
     throws TeiidComponentException, QueryPlannerException {
   try {
     command = (Command) command.clone();
     boolean aliasGroups =
         modelID != null
             && (CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder)
                 || CapabilitiesUtil.supports(
                     Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
     boolean aliasColumns =
         modelID != null
             && (CapabilitiesUtil.supports(
                     Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder)
                 || CapabilitiesUtil.supports(
                     Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
     AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns);
     SourceHint sh = command.getSourceHint();
     if (sh != null && aliasGroups) {
       VDBMetaData vdb = context.getDQPWorkContext().getVDB();
       ModelMetaData model = vdb.getModel(aNode.getModelName());
       List<String> sourceNames = model.getSourceNames();
       SpecificHint sp = null;
       if (sourceNames.size() == 1) {
         sp = sh.getSpecificHint(sourceNames.get(0));
       }
       if (sh.isUseAliases() || (sp != null && sp.isUseAliases())) {
         visitor.setAliasMapping(context.getAliasMapping());
       }
     }
     List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
     if (!references.isEmpty()) {
       Set<String> correleatedGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
       for (Reference ref : references) {
         if (ref.isCorrelated() && ref.getExpression().getGroupSymbol() != null) {
           correleatedGroups.add(ref.getExpression().getGroupSymbol().getName());
         }
       }
       visitor.setCorrelationGroups(correleatedGroups);
     }
     command.acceptVisitor(visitor);
   } catch (QueryMetadataException err) {
     throw new TeiidComponentException(QueryPlugin.Event.TEIID30249, err);
   } catch (TeiidRuntimeException e) {
     if (e.getCause() instanceof QueryPlannerException) {
       throw (QueryPlannerException) e.getCause();
     }
     throw e;
   }
   return command;
 }
Ejemplo n.º 3
0
 public void addExpressionParam(String paramName) {
   ParamInfo paramInfo = null;
   if (exprParams == null) {
     exprParams = new HashMap();
   } else {
     paramInfo = (ParamInfo) exprParams.get(paramName);
   }
   if (paramInfo == null) {
     paramInfo = new ParamInfo(paramName, exprParamType);
     exprParams.put(paramName, paramInfo);
   }
   paramInfo.addParamIndex(paramIndexGenerator.getNewIndex());
 }
Ejemplo n.º 4
0
  public void copyExpressionParams(int count) {
    if (exprParams != null && count > 0) {
      int paramCount = 0;
      // calculate param count first
      for (Iterator it = exprParams.values().iterator(); it.hasNext(); ) {
        ParamInfo info = (ParamInfo) it.next();
        paramCount += info.getIndexList().size();
      }

      for (Iterator it = exprParams.values().iterator(); it.hasNext(); ) {
        ParamInfo info = (ParamInfo) it.next();
        List l = (List) ((ArrayList) info.getIndexList()).clone();
        for (int i = 0, n = l.size(); i < n; i++) {
          int index = ((Integer) l.get(i)).intValue();
          for (int j = 1; j <= count; j++) {
            info.addParamIndex(index + j * paramCount);
          }
        }
      }
      paramIndexGenerator.increase(paramCount * count);
    }
  }