示例#1
0
  @Test
  public void testSerializeDeserialize() throws IOException {
    CounterContext.ContextState state = CounterContext.ContextState.allocate(4, 2);
    state.writeElement(NodeId.fromInt(1), 4L, 4L);
    state.writeElement(NodeId.fromInt(2), 4L, 4L, true);
    state.writeElement(NodeId.fromInt(3), 4L, 4L);
    state.writeElement(NodeId.fromInt(4), 4L, 4L, true);

    CounterColumn original = new CounterColumn(ByteBufferUtil.bytes("x"), state.context, 1L);
    DataOutputBuffer bufOut = new DataOutputBuffer();
    Column.serializer().serialize(original, bufOut);
    byte[] serialized = bufOut.getData();

    ByteArrayInputStream bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterColumn deserialized =
        (CounterColumn) Column.serializer().deserialize(new DataInputStream(bufIn));
    assert original.equals(deserialized);

    bufIn = new ByteArrayInputStream(serialized, 0, serialized.length);
    CounterColumn deserializedOnRemote =
        (CounterColumn) Column.serializer().deserialize(new DataInputStream(bufIn), null, true);
    assert deserializedOnRemote.name().equals(original.name());
    assert deserializedOnRemote.total() == original.total();
    assert deserializedOnRemote.value().equals(cc.clearAllDelta(original.value()));
    assert deserializedOnRemote.timestamp() == deserialized.timestamp();
    assert deserializedOnRemote.timestampOfLastDelete() == deserialized.timestampOfLastDelete();
  }
示例#2
0
  @BeforeClass
  public static void setUp() {
    eno = new Column("ENO", new FieldType(Type.INTEGER, 3), true);
    name = new Column("Name", new FieldType(Type.CHARACTER, 15), false);
    age = new Column("Age", new FieldType(Type.INTEGER, 3), false);
    bday = new Column("Birthdate", new FieldType(Type.DATE), false);

    eno.setNext(name);
    name.setNext(age);
    age.setNext(bday);

    table = new Table("Employee", eno);
  }
示例#3
0
  @Test
  public void testSelectWithRows() throws Exception {
    Table table = new Table("Employee", eno);
    ArrayList<Column> cols = new ArrayList<Column>();
    cols.add(eno);
    cols.add(name);
    cols.add(age);
    cols.add(bday);

    String expectedResult =
        eno.getName()
            + " | "
            + name.getName()
            + " | "
            + age.getName()
            + " | "
            + bday.getName()
            + "\n";
    Record r = new Record();
    Field f1 = new Field(eno, "0");
    Field f2 = new Field(name, "Jake");
    Field f3 = new Field(age, "22");
    Field f4 = new Field(bday, "6/6/94");
    r.addField(f1);
    r.addField(f2);
    r.addField(f3);
    r.addField(f4);

    expectedResult += "0 | Jake | 22 | 6/6/94\n";

    Record r1 = new Record();
    Field g1 = new Field(eno, "1");
    Field g2 = new Field(name, "Gabby");
    Field g3 = new Field(age, "21");
    Field g4 = new Field(bday, "3/21/15");
    r1.addField(g1);
    r1.addField(g2);
    r1.addField(g3);
    r1.addField(g4);

    expectedResult += "1 | Gabby | 21 | 3/21/15\n";

    table.addRecord(r);
    table.addRecord(r1);

    assertEquals(expectedResult, table.select(cols));
  }
示例#4
0
  @Test
  public void testAlterTableRemoveColumnOptions() throws Exception {
    String ddl =
        "CREATE FOREIGN TABLE G1( e1 integer OPTIONS (NULL_VALUE_COUNT 12, FOO 'BAR'), e2 varchar, e3 date);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP NULL_VALUE_COUNT);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS(DROP FOO);"
            + "ALTER FOREIGN TABLE G1 ALTER COLUMN e1 OPTIONS( ADD x 'y');";

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

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

    assertNull(c.getProperty("FOO", false));
    assertEquals(-1, c.getNullValues());
    assertEquals("y", c.getProperty("x", false));
  }
示例#5
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());
  }
示例#6
0
  @Test
  public void testSelectJustColumns() throws Exception {
    Table table = new Table("Employee", eno);
    ArrayList<Column> cols = new ArrayList<Column>();
    cols.add(eno);
    cols.add(name);
    cols.add(age);
    cols.add(bday);

    String result = table.select(cols);

    assertEquals(
        eno.getName()
            + " | "
            + name.getName()
            + " | "
            + age.getName()
            + " | "
            + bday.getName()
            + "\n",
        result);
  }
示例#7
0
  private boolean isClonedSchema(Schema origSchema, Schema newSchema) {
    // Check schema of tables
    boolean schemaEqual = (origSchema.size() == newSchema.size());
    if (schemaEqual == false) {
      fail("Number of columns in schema not equal");
      return false;
    }

    for (int col = 0; col < origSchema.size(); col++) {
      Column colA = origSchema.getColumn(col);
      Column colB = newSchema.getColumn(col);
      if (colA.getSimpleName().equals(colB.getSimpleName()) == false) {
        fail("Column names at index " + col + " do not match");
        return false;
      }
      if (colA.getDataType().equals(colB.getDataType()) == false) {
        fail("Column datatypes at index " + col + " do not match");
        return false;
      }
    }
    return true;
  }
示例#8
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());
  }