Exemplo n.º 1
0
  private String buildTableOptions(Table table) {
    StringBuilder options = new StringBuilder();
    addCommonOptions(options, table);

    if (table.isMaterialized()) {
      addOption(options, MATERIALIZED, table.isMaterialized());
      if (table.getMaterializedTable() != null) {
        addOption(options, MATERIALIZED_TABLE, table.getMaterializedTable().getName());
      }
    }
    if (table.supportsUpdate()) {
      addOption(options, UPDATABLE, table.supportsUpdate());
    }
    if (table.getCardinality() != -1) {
      if (table.getCardinality() != table.getCardinalityAsFloat()) {
        addOption(options, CARDINALITY, (long) table.getCardinalityAsFloat());
      } else {
        addOption(options, CARDINALITY, table.getCardinality());
      }
    }
    if (!table.getProperties().isEmpty()) {
      for (String key : table.getProperties().keySet()) {
        addOption(options, key, table.getProperty(key, false));
      }
    }
    return options.toString();
  }
Exemplo n.º 2
0
  @Test
  public void testView() throws Exception {
    String ddl =
        "CREATE View G1( e1 integer, e2 varchar) OPTIONS (CARDINALITY 12) AS select e1, e2 from foo.bar";

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

    Table table = tableMap.get("G1");

    assertEquals("SELECT e1, e2 FROM foo.bar", table.getSelectTransformation());
    assertEquals(12, table.getCardinality());
  }
Exemplo n.º 3
0
  @Test
  public void testAlterTableDropOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date) OPTIONS(CARDINALITY 12, FOO 'BAR');"
            + "ALTER FOREIGN TABLE G1 OPTIONS(DROP CARDINALITY);"
            + "ALTER FOREIGN TABLE G1 OPTIONS(DROP FOO);";

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

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertEquals(-1, table.getCardinality());
    assertNull(table.getProperty("FOO", false));
  }
Exemplo n.º 4
0
  @Test
  public void testAlterTableAddColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 OPTIONS(ADD CARDINALITY 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD NULL_VALUE_COUNT 12);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(ADD FOO 'BAR');";

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

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertEquals(12, table.getCardinality());
    Column c = table.getColumnByName("e1");
    assertNotNull(c);

    assertEquals("BAR", c.getProperty("FOO", false));
    assertEquals(12, c.getNullValues());
  }
Exemplo n.º 5
0
  @Test
  public void testForeignTable() throws Exception {

    String ddl =
        "CREATE FOREIGN TABLE G1(\n"
            + "e1 integer primary key,\n"
            + "e2 varchar(10) unique,\n"
            + "e3 date not null unique,\n"
            + "e4 decimal(12,3) default 12.2 options (searchable 'unsearchable'),\n"
            + "e5 integer auto_increment INDEX OPTIONS (UUID 'uuid', NAMEINSOURCE 'nis', SELECTABLE 'NO'),\n"
            + "e6 varchar index default 'hello')\n"
            + "OPTIONS (CARDINALITY 12, UUID 'uuid2',  UPDATABLE 'true', FOO 'BAR', ANNOTATION 'Test Table')";

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

    assertTrue("Table not found", tableMap.containsKey("G1"));
    Table table = tableMap.get("G1");
    assertTrue(table.isPhysical());
    assertFalse(table.isVirtual());
    assertFalse(table.isSystem());
    assertFalse(table.isMaterialized());
    assertFalse(table.isDeletePlanEnabled());
    assertEquals("uuid2", table.getUUID());
    assertEquals(12, table.getCardinality());
    assertTrue(table.supportsUpdate());
    assertEquals("BAR", table.getProperties().get("FOO"));
    assertEquals("Test Table", table.getAnnotation());

    assertEquals(6, table.getColumns().size());

    List<Column> columns = table.getColumns();
    Column e1 = columns.get(0);
    Column e2 = columns.get(1);
    Column e3 = columns.get(2);
    Column e4 = columns.get(3);
    Column e5 = columns.get(4);
    Column e6 = columns.get(5);

    assertEquals("e1", e1.getName());
    assertEquals("int", e1.getDatatype().getName());
    assertEquals("primary key not same", e1, table.getPrimaryKey().getColumns().get(0));

    assertEquals("e2", e2.getName());
    assertEquals("string", e2.getDatatype().getName());
    assertEquals("unique", e2, table.getUniqueKeys().get(0).getColumns().get(0));
    assertEquals(NullType.Nullable, e2.getNullType());
    assertEquals(10, e2.getLength());
    assertEquals(0, e2.getPrecision());

    assertEquals("e3", e3.getName());
    assertEquals("date", e3.getDatatype().getName());
    assertEquals("unique", e3, table.getUniqueKeys().get(1).getColumns().get(0));
    assertEquals(NullType.No_Nulls, e3.getNullType());

    assertEquals("e4", e4.getName());
    assertEquals("bigdecimal", e4.getDatatype().getName());
    assertEquals(false, e4.isAutoIncremented());
    assertEquals(12, e4.getPrecision());
    assertEquals(3, e4.getScale());
    assertEquals(SearchType.Unsearchable, e4.getSearchType());
    assertEquals("12.2", e4.getDefaultValue());

    assertEquals("e5", e5.getName());
    assertEquals("int", e5.getDatatype().getName());
    assertEquals(true, e5.isAutoIncremented());
    assertEquals("uuid", e5.getUUID());
    assertEquals("nis", e5.getNameInSource());
    assertEquals(false, e5.isSelectable());
    assertEquals("index", e5, table.getIndexes().get(0).getColumns().get(0));

    assertEquals("e6", e6.getName());
    assertEquals("string", e6.getDatatype().getName());
    assertEquals("index", e6, table.getIndexes().get(1).getColumns().get(0));
    assertEquals("hello", e6.getDefaultValue());
  }