Search in sources :

Example 66 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class TestSchemaBuilder method testStandaloneRepeatedListBuilder.

@Test
public void testStandaloneRepeatedListBuilder() {
    ColumnMetadata columnMetadata = new RepeatedListBuilder("l").addMapArray().addNullable("v", MinorType.VARCHAR).add("i", MinorType.INT).resumeList().buildColumn();
    assertTrue(columnMetadata.isArray());
    assertEquals("l", columnMetadata.name());
    assertEquals(MinorType.LIST, columnMetadata.type());
    ColumnMetadata child = columnMetadata.childSchema();
    assertEquals("l", child.name());
    assertTrue(child.isArray());
    assertTrue(child.isMap());
    TupleMetadata mapSchema = child.tupleSchema();
    ColumnMetadata col0 = mapSchema.metadata(0);
    assertEquals("v", col0.name());
    assertEquals(MinorType.VARCHAR, col0.type());
    assertTrue(col0.isNullable());
    ColumnMetadata col1 = mapSchema.metadata(1);
    assertEquals("i", col1.name());
    assertEquals(MinorType.INT, col1.type());
    assertFalse(col1.isNullable());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) RepeatedListBuilder(org.apache.drill.exec.record.metadata.RepeatedListBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 67 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class TestSchemaBuilder method testRowPreBuilt.

@Test
public void testRowPreBuilt() {
    MaterializedField aField = MaterializedField.create("a", Types.optional(MinorType.VARCHAR));
    ColumnMetadata bCol = MetadataUtils.newScalar("b", MinorType.INT, DataMode.REQUIRED);
    SchemaBuilder builder = new SchemaBuilder().add(aField);
    // Internal method, does not return builder itself.
    builder.addColumn(bCol);
    TupleMetadata schema = builder.buildSchema();
    assertEquals(2, schema.size());
    ColumnMetadata a = schema.metadata(0);
    assertEquals("a", a.name());
    assertEquals(MinorType.VARCHAR, a.type());
    assertEquals(DataMode.OPTIONAL, a.mode());
    ColumnMetadata b = schema.metadata(1);
    assertEquals("b", b.name());
    assertEquals(MinorType.INT, b.type());
    assertEquals(DataMode.REQUIRED, b.mode());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) MaterializedField(org.apache.drill.exec.record.MaterializedField) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 68 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class TestSchemaBuilder method testMapInRow.

/**
 * Tests creating a map within a row.
 * Also the basic map add column methods.
 */
@Test
public void testMapInRow() {
    TupleMetadata schema = new SchemaBuilder().addMap("m").add("a", MinorType.VARCHAR, // Generic
    DataMode.OPTIONAL).add("b", // Required
    MinorType.INT).addNullable("c", // Convenience
    MinorType.FLOAT8).addArray("d", // Convenience
    MinorType.BIGINT).resumeSchema().buildSchema();
    assertEquals(1, schema.size());
    ColumnMetadata m = schema.metadata(0);
    assertEquals("m", m.name());
    assertTrue(m.isMap());
    assertEquals(DataMode.REQUIRED, m.mode());
    TupleMetadata mapSchema = m.tupleSchema();
    assertNotNull(mapSchema);
    assertEquals(4, mapSchema.size());
    ColumnMetadata a = mapSchema.metadata(0);
    assertEquals("a", a.name());
    assertEquals(MinorType.VARCHAR, a.type());
    assertEquals(DataMode.OPTIONAL, a.mode());
    ColumnMetadata b = mapSchema.metadata(1);
    assertEquals("b", b.name());
    assertEquals(MinorType.INT, b.type());
    assertEquals(DataMode.REQUIRED, b.mode());
    ColumnMetadata c = mapSchema.metadata(2);
    assertEquals("c", c.name());
    assertEquals(MinorType.FLOAT8, c.type());
    assertEquals(DataMode.OPTIONAL, c.mode());
    ColumnMetadata d = mapSchema.metadata(3);
    assertEquals("d", d.name());
    assertEquals(MinorType.BIGINT, d.type());
    assertEquals(DataMode.REPEATED, d.mode());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 69 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class TestSchemaBuilder method testMapInRepeatedList.

// Note: union-in-union not supported in Drill
@Test
public void testMapInRepeatedList() {
    TupleMetadata schema = new SchemaBuilder().addRepeatedList("x").addMapArray().add("a", MinorType.INT).addNullable("b", MinorType.VARCHAR).resumeList().resumeSchema().buildSchema();
    ColumnMetadata list = schema.metadata("x");
    ColumnMetadata mapCol = list.childSchema();
    assertTrue(mapCol.isMap());
    TupleMetadata mapSchema = mapCol.tupleSchema();
    ColumnMetadata a = mapSchema.metadata("a");
    assertEquals(MinorType.INT, a.type());
    assertEquals(DataMode.REQUIRED, a.mode());
    ColumnMetadata b = mapSchema.metadata("b");
    assertEquals(MinorType.VARCHAR, b.type());
    assertEquals(DataMode.OPTIONAL, b.mode());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) SchemaBuilder(org.apache.drill.exec.record.metadata.SchemaBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 70 with ColumnMetadata

use of org.apache.drill.exec.record.metadata.ColumnMetadata in project drill by apache.

the class TestSchemaBuilder method testStandaloneMapBuilder.

@Test
public void testStandaloneMapBuilder() {
    ColumnMetadata columnMetadata = new MapBuilder("m1", DataMode.OPTIONAL).addNullable("b", MinorType.BIGINT).addMap("m2").addNullable("v", MinorType.VARCHAR).resumeMap().buildColumn();
    assertTrue(columnMetadata.isMap());
    assertTrue(columnMetadata.isNullable());
    assertEquals("m1", columnMetadata.name());
    TupleMetadata schema = columnMetadata.tupleSchema();
    ColumnMetadata col0 = schema.metadata(0);
    assertEquals("b", col0.name());
    assertEquals(MinorType.BIGINT, col0.type());
    assertTrue(col0.isNullable());
    ColumnMetadata col1 = schema.metadata(1);
    assertEquals("m2", col1.name());
    assertTrue(col1.isMap());
    assertFalse(col1.isNullable());
    ColumnMetadata child = col1.tupleSchema().metadata(0);
    assertEquals("v", child.name());
    assertEquals(MinorType.VARCHAR, child.type());
    assertTrue(child.isNullable());
}
Also used : ColumnMetadata(org.apache.drill.exec.record.metadata.ColumnMetadata) TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) MapBuilder(org.apache.drill.exec.record.metadata.MapBuilder) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Aggregations

ColumnMetadata (org.apache.drill.exec.record.metadata.ColumnMetadata)195 Test (org.junit.Test)104 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)98 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)50 DrillTest (org.apache.drill.test.DrillTest)37 PrimitiveColumnMetadata (org.apache.drill.exec.record.metadata.PrimitiveColumnMetadata)31 SubOperatorTest (org.apache.drill.test.SubOperatorTest)31 BaseTest (org.apache.drill.test.BaseTest)26 MapColumnMetadata (org.apache.drill.exec.record.metadata.MapColumnMetadata)20 SchemaBuilder (org.apache.drill.test.rowSet.schema.SchemaBuilder)20 VariantColumnMetadata (org.apache.drill.exec.record.metadata.VariantColumnMetadata)19 VariantMetadata (org.apache.drill.exec.record.metadata.VariantMetadata)19 AbstractColumnMetadata (org.apache.drill.exec.record.metadata.AbstractColumnMetadata)17 ScalarWriter (org.apache.drill.exec.vector.accessor.ScalarWriter)17 DictColumnMetadata (org.apache.drill.exec.record.metadata.DictColumnMetadata)15 EvfTest (org.apache.drill.categories.EvfTest)13 ProjectionFilter (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter)13 TupleSchema (org.apache.drill.exec.record.metadata.TupleSchema)11 ArrayList (java.util.ArrayList)10 ProjResult (org.apache.drill.exec.physical.resultSet.impl.ProjectionFilter.ProjResult)10