Esempio n. 1
0
  @Test
  public void testCreateAndGetNestedTable2() throws Exception {
    // schema creation
    // three level nested schema
    //
    // s1
    //  |- s2
    //  |- s3
    //      |- s1
    //      |- s2
    //          |- s3
    //              |- s1
    //      |- s3
    //  |- s4

    SchemaBuilder nestedSchema = SchemaBuilder.builder();
    nestedSchema.add("s1", Type.INT8);
    nestedSchema.add("s2", Type.INT8);

    Schema s5 = SchemaBuilder.builder().add("s6", Type.INT8).build();

    SchemaBuilder s7 = SchemaBuilder.builder();
    s7.add("s5", new TypeDesc(s5));

    SchemaBuilder s3 = SchemaBuilder.builder();
    s3.add("s4", Type.INT8);
    s3.add("s7", new TypeDesc(s7.build()));
    s3.add("s8", Type.INT8);

    nestedSchema.add("s3", new TypeDesc(s3.build()));
    nestedSchema.add("s9", Type.INT8);

    assertSchemaEquality("nested_schema2", nestedSchema.build());
  }
Esempio n. 2
0
  @Test
  public final void testAddAndDeleteTablePartitionByRange() throws Exception {
    Schema schema =
        SchemaBuilder.builder()
            .add("id", Type.INT4)
            .add("name", Type.TEXT)
            .add("age", Type.INT4)
            .add("score", Type.FLOAT8)
            .build();

    String tableName =
        IdentifierUtil.buildFQName(TajoConstants.DEFAULT_DATABASE_NAME, "addedtable");
    KeyValueSet opts = new KeyValueSet();
    opts.set("file.delimiter", ",");
    TableMeta meta = CatalogUtil.newTableMeta("TEXT", opts);

    Schema partSchema = SchemaBuilder.builder().add("id", Type.INT4).build();
    PartitionMethodDesc partitionDesc =
        new PartitionMethodDesc(
            DEFAULT_DATABASE_NAME, tableName, CatalogProtos.PartitionType.RANGE, "id", partSchema);

    TableDesc desc =
        new TableDesc(
            tableName,
            schema,
            meta,
            new Path(CommonTestingUtil.getTestDir(), "addedtable").toUri());
    desc.setPartitionMethod(partitionDesc);
    assertFalse(catalog.existsTable(tableName));
    catalog.createTable(desc);
    assertTrue(catalog.existsTable(tableName));

    TableDesc retrieved = catalog.getTableDesc(tableName);

    assertEquals(retrieved.getName(), tableName);
    assertEquals(
        retrieved.getPartitionMethod().getPartitionType(), CatalogProtos.PartitionType.RANGE);
    assertEquals(
        retrieved.getPartitionMethod().getExpressionSchema().getColumn(0).getSimpleName(), "id");

    catalog.dropTable(tableName);
    assertFalse(catalog.existsTable(tableName));
  }
Esempio n. 3
0
 private TableDesc createMockupTable(String databaseName, String tableName) throws IOException {
   schema1 =
       SchemaBuilder.builder()
           .add(FieldName1, Type.BLOB)
           .add(FieldName2, Type.INT4)
           .add(FieldName3, Type.INT8)
           .build();
   Path path = new Path(CommonTestingUtil.getTestDir(), tableName);
   TableDesc table =
       new TableDesc(
           IdentifierUtil.buildFQName(databaseName, tableName),
           schema1,
           new TableMeta("TEXT", new KeyValueSet()),
           path.toUri(),
           true);
   return table;
 }
Esempio n. 4
0
  public static TableDesc prepareTable() throws IOException {
    relationSchema =
        SchemaBuilder.builder()
            .add(DEFAULT_DATABASE_NAME + ".indexed.id", Type.INT4)
            .add(DEFAULT_DATABASE_NAME + ".indexed.name", Type.TEXT)
            .add(DEFAULT_DATABASE_NAME + ".indexed.age", Type.INT4)
            .add(DEFAULT_DATABASE_NAME + ".indexed.score", Type.FLOAT8)
            .build();

    String tableName = "indexed";

    TableMeta meta = CatalogUtil.newTableMeta(BuiltinStorages.TEXT, server.getConf());
    return new TableDesc(
        IdentifierUtil.buildFQName(TajoConstants.DEFAULT_DATABASE_NAME, tableName),
        relationSchema,
        meta,
        new Path(CommonTestingUtil.getTestDir(), "indexed").toUri());
  }
Esempio n. 5
0
  @Test
  public void testGetTable() throws Exception {
    schema1 =
        SchemaBuilder.builder()
            .add(FieldName1, Type.BLOB)
            .add(FieldName2, Type.INT4)
            .add(FieldName3, Type.INT8)
            .build();
    Path path = new Path(CommonTestingUtil.getTestDir(), "table1");
    TableDesc meta =
        new TableDesc(
            IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "getTable"),
            schema1,
            "TEXT",
            new KeyValueSet(),
            path.toUri());

    assertFalse(catalog.existsTable(DEFAULT_DATABASE_NAME, "getTable"));
    catalog.createTable(meta);
    assertTrue(catalog.existsTable(DEFAULT_DATABASE_NAME, "getTable"));

    catalog.dropTable(IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, "getTable"));
    assertFalse(catalog.existsTable(DEFAULT_DATABASE_NAME, "getTable"));
  }
Esempio n. 6
0
  // TODO: This should be added at TAJO-1891
  public final void testAddAndDeleteTablePartitionByColumn() throws Exception {
    Schema schema =
        SchemaBuilder.builder()
            .add("id", Type.INT4)
            .add("name", Type.TEXT)
            .add("age", Type.INT4)
            .add("score", Type.FLOAT8)
            .build();

    String simpleTableName = "addedtable";
    String tableName = IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, simpleTableName);
    KeyValueSet opts = new KeyValueSet();
    opts.set("file.delimiter", ",");
    TableMeta meta = CatalogUtil.newTableMeta("TEXT", opts);

    Schema partSchema = SchemaBuilder.builder().add("id", Type.INT4).add("name", Type.TEXT).build();

    PartitionMethodDesc partitionMethodDesc =
        new PartitionMethodDesc(
            DEFAULT_DATABASE_NAME,
            tableName,
            CatalogProtos.PartitionType.COLUMN,
            "id,name",
            partSchema);

    TableDesc desc =
        new TableDesc(
            tableName,
            schema,
            meta,
            new Path(CommonTestingUtil.getTestDir(), simpleTableName).toUri());
    desc.setPartitionMethod(partitionMethodDesc);
    assertFalse(catalog.existsTable(tableName));
    catalog.createTable(desc);
    assertTrue(catalog.existsTable(tableName));

    TableDesc retrieved = catalog.getTableDesc(tableName);

    assertEquals(retrieved.getName(), tableName);
    assertEquals(
        retrieved.getPartitionMethod().getPartitionType(), CatalogProtos.PartitionType.COLUMN);
    assertEquals(
        retrieved.getPartitionMethod().getExpressionSchema().getColumn(0).getSimpleName(), "id");

    testAddPartition(tableName, "id=10/name=aaa");
    testAddPartition(tableName, "id=20/name=bbb");

    List<CatalogProtos.PartitionDescProto> partitions =
        catalog.getPartitionsOfTable(DEFAULT_DATABASE_NAME, simpleTableName);
    assertNotNull(partitions);
    assertEquals(partitions.size(), 2);
    assertEquals(partitions.get(0).getNumBytes(), 0L);

    testGetPartitionsByAlgebra(DEFAULT_DATABASE_NAME, simpleTableName);

    testDropPartition(tableName, "id=10/name=aaa");
    testDropPartition(tableName, "id=20/name=bbb");

    partitions = catalog.getPartitionsOfTable(DEFAULT_DATABASE_NAME, simpleTableName);
    assertNotNull(partitions);
    assertEquals(partitions.size(), 0);

    catalog.dropTable(tableName);
    assertFalse(catalog.existsTable(tableName));
  }