Ejemplo n.º 1
0
 /** This method returns new AttributeList by replacing all source names with a new source name. */
 public AttributeList renameAllSourceNames(String to) {
   AttributeList rval = copy();
   for (int i = 0; i < rval.attr.size(); i++) {
     if (rval.isAttribute(i)) {
       Attribute a = rval.getAttribute(i);
       rval.attr.set(i, new Attribute(to, a.getColumnName()));
     } else if (rval.isFunction(i)) {
       FunctionParameter f = rval.getFunction(i);
       AttributeList args = f.getArguments().renameAllSourceNames(to);
       rval.attr.set(i, new FunctionParameter(f.getFunctionName(), args));
     }
   }
   return rval;
 }
Ejemplo n.º 2
0
 /** This method returns new AttributeList by replaceing given column name with new column name. */
 public AttributeList renameColumnName(String from, String to) {
   AttributeList rval = copy();
   if (from == null || to == null || from.equals(to)) return rval;
   for (int i = 0; i < rval.attr.size(); i++) {
     if (rval.isAttribute(i)) {
       Attribute a = rval.getAttribute(i);
       if (a.getColumnName().equals(from)) rval.attr.set(i, new Attribute(a.getSourceName(), to));
     } else if (rval.isFunction(i)) {
       FunctionParameter f = rval.getFunction(i);
       AttributeList args = f.getArguments().renameColumnName(from, to);
       rval.attr.set(i, new FunctionParameter(f.getFunctionName(), args));
     }
   }
   return rval;
 }
Ejemplo n.º 3
0
 private SqlOperator toOp(SqlIdentifier name, Function function) {
   List<RelDataType> argTypes = new ArrayList<RelDataType>();
   List<SqlTypeFamily> typeFamilies = new ArrayList<SqlTypeFamily>();
   for (FunctionParameter o : function.getParameters()) {
     final RelDataType type = o.getType(typeFactory);
     argTypes.add(type);
     typeFamilies.add(Util.first(type.getSqlTypeName().getFamily(), SqlTypeFamily.ANY));
   }
   final RelDataType returnType;
   if (function instanceof ScalarFunction) {
     return new SqlUserDefinedFunction(
         name,
         ReturnTypes.explicit(Schemas.proto((ScalarFunction) function)),
         InferTypes.explicit(argTypes),
         OperandTypes.family(typeFamilies),
         toSql(argTypes),
         function);
   } else if (function instanceof AggregateFunction) {
     returnType = ((AggregateFunction) function).getReturnType(typeFactory);
     return new SqlUserDefinedAggFunction(
         name,
         ReturnTypes.explicit(returnType),
         InferTypes.explicit(argTypes),
         OperandTypes.family(typeFamilies),
         (AggregateFunction) function);
   } else if (function instanceof TableMacro) {
     return new SqlUserDefinedTableMacro(
         name,
         ReturnTypes.CURSOR,
         InferTypes.explicit(argTypes),
         OperandTypes.family(typeFamilies),
         (TableMacro) function);
   } else if (function instanceof TableFunction) {
     return new SqlUserDefinedTableFunction(
         name,
         ReturnTypes.CURSOR,
         InferTypes.explicit(argTypes),
         OperandTypes.family(typeFamilies),
         toSql(argTypes),
         (TableFunction) function);
   } else {
     throw new AssertionError("unknown function type " + function);
   }
 }
Ejemplo n.º 4
0
 public static AttributeList parse(String str) throws StreamSpinnerException {
   AttributeList rval = new AttributeList();
   String[] tokens = str.split("\\s*,\\s*");
   String buf = "";
   for (int i = 0; tokens != null && i < tokens.length; i++) {
     buf = buf + tokens[i];
     if (buf.indexOf("(") >= 0 && (!FunctionParameter.isFunction(buf))) {
       buf = buf + ",";
       continue;
     }
     rval.add(buf);
     buf = "";
   }
   if (!buf.equals("")) throw new StreamSpinnerException("Cannot parse string : " + str);
   return rval;
 }
Ejemplo n.º 5
0
 private void visit(FunctionParameter param) {
   if (param.isVarArg()) {
     append(NonReserved.VARIADIC).append(SPACE);
   }
   appendColumn(param, true, true);
 }
Ejemplo n.º 6
0
 public void add(String str) {
   if (FunctionParameter.isFunction(str)) attr.add(new FunctionParameter(str));
   else if (Attribute.isAttribute(str)) attr.add(new Attribute(str));
   else attr.add(new String(str));
 }