Exemplo n.º 1
0
 public final Table getTable(String tableName, boolean caseSensitive) {
   if (caseSensitive) {
     return compositeTableMap.get(tableName);
   } else {
     final TableEntry tableEntry = tableMapInsensitive.get(tableName);
     if (tableEntry != null) {
       return tableEntry.getTable();
     }
     final FunctionEntry entry = nullaryFunctionMapInsensitive.get(tableName);
     if (entry != null) {
       return ((TableMacro) entry.getFunction()).apply(ImmutableList.of());
     }
     for (String name : schema.getTableNames()) {
       if (name.equalsIgnoreCase(tableName)) {
         return schema.getTable(name);
       }
     }
     return null;
   }
 }
Exemplo n.º 2
0
 public OptiqSchema(OptiqSchema parent, final Schema schema, String name) {
   this.parent = parent;
   this.schema = schema;
   this.name = name;
   assert (parent == null) == (this instanceof OptiqRootSchema);
   //noinspection unchecked
   this.compositeTableMap =
       CompositeMap.of(
           Maps.transformValues(
               tableMap,
               new com.google.common.base.Function<TableEntry, Table>() {
                 public Table apply(TableEntry input) {
                   return input.getTable();
                 }
               }),
           Maps.transformValues(
               Multimaps.filterEntries(
                       functionMap,
                       new Predicate<Map.Entry<String, FunctionEntry>>() {
                         public boolean apply(Map.Entry<String, FunctionEntry> entry) {
                           final Function function = entry.getValue().getFunction();
                           return function instanceof TableMacro
                               && function.getParameters().isEmpty();
                         }
                       })
                   .asMap(),
               new com.google.common.base.Function<Collection<FunctionEntry>, Table>() {
                 public Table apply(Collection<FunctionEntry> input) {
                   // At most one function with zero parameters.
                   final TableMacro tableMacro =
                       (TableMacro) input.iterator().next().getFunction();
                   return tableMacro.apply(ImmutableList.of());
                 }
               }),
           Compatible.INSTANCE.asMap(
               schema.getTableNames(),
               new com.google.common.base.Function<String, Table>() {
                 public Table apply(String input) {
                   return schema.getTable(input);
                 }
               }));
   // TODO: include schema's functions in this map.
   this.compositeFunctionMap =
       Multimaps.transformValues(
           functionMap,
           new com.google.common.base.Function<FunctionEntry, Function>() {
             public Function apply(FunctionEntry input) {
               return input.getFunction();
             }
           });
   //noinspection unchecked
   this.compositeSubSchemaMap =
       CompositeMap.of(
           subSchemaMap,
           Compatible.INSTANCE.asMap(
               schema.getSubSchemaNames(),
               new com.google.common.base.Function<String, OptiqSchema>() {
                 public OptiqSchema apply(String name) {
                   return add(name, schema.getSubSchema(name));
                 }
               }));
 }