Esempio n. 1
0
 public RelOptTableImpl getTable(final String[] names) {
   List<Pair<String, Object>> pairs = new ArrayList<Pair<String, Object>>();
   Schema schema2 = schema;
   for (int i = 0; i < names.length; i++) {
     final String name = names[i];
     Schema subSchema = schema2.getSubSchema(name);
     if (subSchema != null) {
       pairs.add(Pair.<String, Object>of(name, subSchema));
       schema2 = subSchema;
       continue;
     }
     final Table table = schema2.getTable(name);
     if (table != null) {
       pairs.add(Pair.<String, Object>of(name, table));
       if (i != names.length - 1) {
         // not enough objects to match all names
         return null;
       }
       return new RelOptTableImpl(
           this, typeFactory.createType(table.getElementType()), names, table);
     }
     return null;
   }
   return null;
 }
Esempio n. 2
0
  @Test
  public void testGlobalTemp() throws Exception {
    String ddl = "CREATE GLOBAL TEMPORARY TABLE T (col string);";

    Schema s = helpParse(ddl, "model").getSchema();
    Table t = s.getTable("T");
    assertEquals(1, t.getColumns().size());
  }
Esempio n. 3
0
  @Test
  public void testArrayType() throws Exception {
    String ddl = "CREATE VIEW V (col string[]) as select ('a','b');";

    Schema s = helpParse(ddl, "model").getSchema();
    Table t = s.getTable("V");
    assertEquals(1, t.getColumns().size());
    assertEquals("string[]", t.getColumns().get(0).getRuntimeType());
    assertEquals(String[].class, t.getColumns().get(0).getJavaType());
  }
Esempio n. 4
0
  /**
   * Adds the tables of the DbUnit dataset to the given schema.
   *
   * @param dbUnitDataSet The DbUnit dataset containing the tables, not null
   * @param schema The schema to add the tables to, not null
   */
  protected void addTables(IDataSet dbUnitDataSet, Schema schema) throws DataSetException {
    ITableIterator dbUnitTableIterator = dbUnitDataSet.iterator();
    while (dbUnitTableIterator.next()) {
      ITable dbUnitTable = dbUnitTableIterator.getTable();
      String tableName = dbUnitTable.getTableMetaData().getTableName();

      List<String> primaryKeyColumnNames = getPrimaryKeyColumnNames(dbUnitTable);

      Table table = schema.getTable(tableName);
      if (table == null) {
        table = new Table(tableName);
        schema.addTable(table);
      }
      addRows(dbUnitTable, table, primaryKeyColumnNames);
    }
  }
Esempio n. 5
0
  @Test
  public void testInsteadOfTriggerIsDistinct() throws Exception {
    String ddl =
        "CREATE VIEW G1( e1 integer, e2 varchar) AS select * from foo;"
            + "CREATE TRIGGER ON G1 INSTEAD OF UPDATE AS "
            + "FOR EACH ROW \n"
            + "BEGIN ATOMIC \n"
            + "if (\"new\" is not distinct from \"old\") raise sqlexception 'error';\n"
            + "END;";

    Schema s = helpParse(ddl, "model").getSchema();

    assertEquals(
        "FOR EACH ROW\nBEGIN ATOMIC\nIF(\"new\" IS NOT DISTINCT FROM \"old\")\nBEGIN\nRAISE SQLEXCEPTION 'error';\nEND\nEND",
        s.getTable("G1").getUpdatePlan());
  }
Esempio n. 6
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;
   }
 }
Esempio n. 7
0
  @Test
  public void testInsteadOfTrigger() throws Exception {
    String ddl =
        "CREATE VIEW G1( e1 integer, e2 varchar) AS select * from foo;"
            + "CREATE TRIGGER ON G1 INSTEAD OF INSERT AS "
            + "FOR EACH ROW \n"
            + "BEGIN ATOMIC \n"
            + "insert into g1 (e1, e2) values (1, 'trig');\n"
            + "END;"
            + "CREATE View G2( e1 integer, e2 varchar) AS select * from foo;";

    Schema s = helpParse(ddl, "model").getSchema();
    Map<String, Table> tableMap = s.getTables();

    assertTrue("Table not found", tableMap.containsKey("G1"));
    assertTrue("Table not found", tableMap.containsKey("G2"));
    assertEquals(
        "FOR EACH ROW\nBEGIN ATOMIC\nINSERT INTO g1 (e1, e2) VALUES (1, 'trig');\nEND",
        s.getTable("G1").getInsertPlan());
  }
Esempio n. 8
0
  /**
   * Appends all rows and tables of the actual schema to the result. Only tables that are in the
   * expected schema will be appended.
   *
   * @param schema The expected schema, not null
   * @param actualSchema The actual schema, not null
   * @param result The result to append to, not null
   */
  protected void appendSchemaContent(Schema schema, Schema actualSchema, StringBuilder result) {
    for (Table table : schema.getTables()) {
      Table actualTable = actualSchema.getTable(table.getName());
      if (actualTable == null) {
        continue;
      }
      appendTableName(schema, actualTable, result);
      result.append("\n");

      if (actualTable.getRows().isEmpty()) {
        result.append("  <empty table>\n");
      } else {
        result.append("  ");
        appendColumnNames(actualTable.getRows().get(0), result);
        result.append("\n");
        for (Row row : actualTable.getRows()) {
          result.append("  ");
          appendRow(row, result);
          result.append("\n");
        }
      }
      result.append("\n");
    }
  }
 public Table getTable(String name) {
   return schema.getTable(name);
 }