Search in sources :

Example 1 with Repetition

use of org.apache.parquet.schema.Type.Repetition in project parquet-mr by apache.

the class MetadataUtils method showDetails.

private static void showDetails(PrettyPrintWriter out, GroupType type, int depth, MessageType container, List<String> cpath) {
    String name = Strings.repeat(".", depth) + type.getName();
    Repetition rep = type.getRepetition();
    int fcount = type.getFieldCount();
    out.format("%s: %s F:%d%n", name, rep, fcount);
    cpath.add(type.getName());
    for (Type ftype : type.getFields()) {
        showDetails(out, ftype, depth + 1, container, cpath);
    }
    cpath.remove(cpath.size() - 1);
}
Also used : PrimitiveType(org.apache.parquet.schema.PrimitiveType) GroupType(org.apache.parquet.schema.GroupType) MessageType(org.apache.parquet.schema.MessageType) Type(org.apache.parquet.schema.Type) OriginalType(org.apache.parquet.schema.OriginalType) Repetition(org.apache.parquet.schema.Type.Repetition)

Example 2 with Repetition

use of org.apache.parquet.schema.Type.Repetition in project parquet-mr by apache.

the class MetadataUtils method showDetails.

private static void showDetails(PrettyPrintWriter out, PrimitiveType type, int depth, MessageType container, List<String> cpath) {
    String name = Strings.repeat(".", depth) + type.getName();
    OriginalType otype = type.getOriginalType();
    Repetition rep = type.getRepetition();
    PrimitiveTypeName ptype = type.getPrimitiveTypeName();
    out.format("%s: %s %s", name, rep, ptype);
    if (otype != null)
        out.format(" O:%s", otype);
    if (container != null) {
        cpath.add(type.getName());
        String[] paths = cpath.toArray(new String[cpath.size()]);
        cpath.remove(cpath.size() - 1);
        ColumnDescriptor desc = container.getColumnDescription(paths);
        int defl = desc.getMaxDefinitionLevel();
        int repl = desc.getMaxRepetitionLevel();
        out.format(" R:%d D:%d", repl, defl);
    }
    out.println();
}
Also used : OriginalType(org.apache.parquet.schema.OriginalType) ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) Repetition(org.apache.parquet.schema.Type.Repetition) PrimitiveTypeName(org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName)

Example 3 with Repetition

use of org.apache.parquet.schema.Type.Repetition in project parquet-mr by apache.

the class MessageTypeParser method addType.

private static void addType(String t, Tokenizer st, Types.GroupBuilder builder) {
    Repetition repetition = asRepetition(t, st);
    // Read type.
    String type = st.nextToken();
    if ("group".equalsIgnoreCase(type)) {
        addGroupType(st, repetition, builder);
    } else {
        addPrimitiveType(st, asPrimitive(type, st), repetition, builder);
    }
}
Also used : Repetition(org.apache.parquet.schema.Type.Repetition)

Example 4 with Repetition

use of org.apache.parquet.schema.Type.Repetition in project parquet-mr by apache.

the class TestTypeBuilders method testPrimitiveTypeConstruction.

@Test
public void testPrimitiveTypeConstruction() {
    PrimitiveTypeName[] types = new PrimitiveTypeName[] { BOOLEAN, INT32, INT64, INT96, FLOAT, DOUBLE, BINARY };
    for (PrimitiveTypeName type : types) {
        String name = type.toString() + "_";
        for (Type.Repetition repetition : Type.Repetition.values()) {
            PrimitiveType expected = new PrimitiveType(repetition, type, name);
            PrimitiveType built = Types.primitive(type, repetition).named(name);
            Assert.assertEquals(expected, built);
            switch(repetition) {
                case REQUIRED:
                    built = Types.required(type).named(name);
                    break;
                case OPTIONAL:
                    built = Types.optional(type).named(name);
                    break;
                case REPEATED:
                    built = Types.repeated(type).named(name);
                    break;
            }
            Assert.assertEquals(expected, built);
        }
    }
}
Also used : OriginalType(org.apache.parquet.schema.OriginalType) Repetition(org.apache.parquet.schema.Type.Repetition) PrimitiveTypeName(org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName) Test(org.junit.Test)

Example 5 with Repetition

use of org.apache.parquet.schema.Type.Repetition in project parquet-mr by apache.

the class TestTypeBuilders method testGroupTypeConstruction.

@Test
public void testGroupTypeConstruction() {
    PrimitiveType f1 = Types.required(BINARY).as(UTF8).named("f1");
    PrimitiveType f2 = Types.required(INT32).named("f2");
    PrimitiveType f3 = Types.optional(INT32).named("f3");
    String name = "group";
    for (Type.Repetition repetition : Type.Repetition.values()) {
        GroupType expected = new GroupType(repetition, name, f1, new GroupType(repetition, "g1", f2, f3));
        GroupType built = Types.buildGroup(repetition).addField(f1).group(repetition).addFields(f2, f3).named("g1").named(name);
        Assert.assertEquals(expected, built);
        switch(repetition) {
            case REQUIRED:
                built = Types.requiredGroup().addField(f1).requiredGroup().addFields(f2, f3).named("g1").named(name);
                break;
            case OPTIONAL:
                built = Types.optionalGroup().addField(f1).optionalGroup().addFields(f2, f3).named("g1").named(name);
                break;
            case REPEATED:
                built = Types.repeatedGroup().addField(f1).repeatedGroup().addFields(f2, f3).named("g1").named(name);
                break;
        }
        Assert.assertEquals(expected, built);
    }
}
Also used : OriginalType(org.apache.parquet.schema.OriginalType) Repetition(org.apache.parquet.schema.Type.Repetition) Test(org.junit.Test)

Aggregations

Repetition (org.apache.parquet.schema.Type.Repetition)8 OriginalType (org.apache.parquet.schema.OriginalType)7 PrimitiveTypeName (org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName)4 PrimitiveType (org.apache.parquet.schema.PrimitiveType)3 Test (org.junit.Test)3 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)2 DecimalMetadata (org.apache.parquet.schema.DecimalMetadata)2 ColumnDescriptor (org.apache.parquet.column.ColumnDescriptor)1 GroupType (org.apache.parquet.schema.GroupType)1 MessageType (org.apache.parquet.schema.MessageType)1 Type (org.apache.parquet.schema.Type)1