Exemplo n.º 1
0
 /** Returns the path of a schema, appending the name of a table if not null. */
 public static List<String> path(Schema schema, String name) {
   final List<String> list = new ArrayList<String>();
   if (name != null) {
     list.add(name);
   }
   for (Schema s = schema; s != null; s = s.getParentSchema()) {
     if (s.getParentSchema() != null || !s.getName().equals("")) {
       // Omit the root schema's name from the path if it's the empty string,
       // which it usually is.
       list.add(s.getName());
     }
   }
   return ImmutableList.copyOf(Lists.reverse(list));
 }
Exemplo n.º 2
0
  public static TableFunction methodMember(final Method method, final JavaTypeFactory typeFactory) {
    final List<Parameter> parameters = new ArrayList<Parameter>();
    for (final Class<?> parameterType : method.getParameterTypes()) {
      parameters.add(
          new Parameter() {
            final int ordinal = parameters.size();
            final RelDataType type = typeFactory.createType(parameterType);

            public int getOrdinal() {
              return ordinal;
            }

            public String getName() {
              return "a" + ordinal;
            }

            public RelDataType getType(RelDataTypeFactory typeFactory) {
              return type;
            }
          });
    }
    return new TableFunction() {
      public List<Parameter> getParameters() {
        return parameters;
      }

      public Table apply(List<Object> arguments) {
        try {
          //noinspection unchecked
          return (Table) method.invoke(null, arguments.toArray());
        } catch (IllegalAccessException e) {
          throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
          throw new RuntimeException(e);
        }
      }

      public RelDataType getRowType(RelDataTypeFactory typeFactory) {
        final Class<?> returnType = method.getReturnType();
        return ((JavaTypeFactory) typeFactory).createType(returnType);
      }
    };
  }
Exemplo n.º 3
0
 public static OptiqSchema.TableFunctionEntry resolve(
     RelDataTypeFactory typeFactory,
     String name,
     Collection<OptiqSchema.TableFunctionEntry> tableFunctions,
     List<RelDataType> argumentTypes) {
   final List<OptiqSchema.TableFunctionEntry> matches =
       new ArrayList<OptiqSchema.TableFunctionEntry>();
   for (OptiqSchema.TableFunctionEntry member : tableFunctions) {
     if (matches(typeFactory, member.getTableFunction(), argumentTypes)) {
       matches.add(member);
     }
   }
   switch (matches.size()) {
     case 0:
       return null;
     case 1:
       return matches.get(0);
     default:
       throw new RuntimeException(
           "More than one match for " + name + " with arguments " + argumentTypes);
   }
 }
Exemplo n.º 4
0
 private static boolean matches(
     RelDataTypeFactory typeFactory, TableFunction member, List<RelDataType> argumentTypes) {
   List<Parameter> parameters = member.getParameters();
   if (parameters.size() != argumentTypes.size()) {
     return false;
   }
   for (int i = 0; i < argumentTypes.size(); i++) {
     RelDataType argumentType = argumentTypes.get(i);
     Parameter parameter = parameters.get(i);
     if (!canConvert(argumentType, parameter.getType(typeFactory))) {
       return false;
     }
   }
   return true;
 }