Package org.apache.hadoop.zebra.types

Examples of org.apache.hadoop.zebra.types.Schema


public class TestSchemaCollection {
  @Test
  public void testSchemaValid1() throws ParseException {
    String strSch = "c1:collection(f1:int, f2:int), c2:collection(c3:collection(f3:float, f4))";
    TableSchemaParser parser;
    Schema schema;

    parser = new TableSchemaParser(new StringReader(strSch));
    schema = parser.RecordSchema(null);
    System.out.println(schema);

    // test 1st level schema;
    ColumnSchema f1 = schema.getColumn(0);
    Assert.assertEquals("c1", f1.name);
    Assert.assertEquals(ColumnType.COLLECTION, f1.type);

    ColumnSchema f2 = schema.getColumn(1);
    Assert.assertEquals("c2", f2.name);
    Assert.assertEquals(ColumnType.COLLECTION, f2.type);

    // test 2nd level schema;
    Schema f1Schema = f1.schema;
    ColumnSchema f11 = f1Schema.getColumn(0);
    Assert.assertEquals("f1", f11.name);
    Assert.assertEquals(ColumnType.INT, f11.type);
    ColumnSchema f12 = f1Schema.getColumn(1);
    Assert.assertEquals("f2", f12.name);
    Assert.assertEquals(ColumnType.INT, f12.type);

    Schema f2Schema = f2.schema;
    ColumnSchema f21 = f2Schema.getColumn(0);
    Assert.assertEquals("c3", f21.name);
    Assert.assertEquals(ColumnType.COLLECTION, f21.type);

    // test 3rd level schema;
    Schema f21Schema = f21.schema;
    ColumnSchema f211 = f21Schema.getColumn(0);
    Assert.assertEquals("f3", f211.name);
    Assert.assertEquals(ColumnType.FLOAT, f211.type);
    ColumnSchema f212 = f21Schema.getColumn(1);
    Assert.assertEquals("f4", f212.name);
    Assert.assertEquals(ColumnType.BYTES, f212.type);
  }
View Full Code Here


  @Test
  public void testSchemaInvalid1() throws ParseException, Exception {
    try {
      String strSch = "c1:collection(f1:int, f2:int), c2:collection(c3:collection(f3:float, f4)))";
      TableSchemaParser parser;
      Schema schema;

      parser = new TableSchemaParser(new StringReader(strSch));
      schema = parser.RecordSchema(null);
      System.out.println(schema);
    } catch (Exception e) {
View Full Code Here

public class TestSchemaRecord {
  @Test
  public void testSchemaValid1() throws ParseException {
    String strSch = "r1:record(f1:int, f2:int), r2:record(r3:record(f3:float, f4))";
    TableSchemaParser parser;
    Schema schema;

    parser = new TableSchemaParser(new StringReader(strSch));
    schema = parser.RecordSchema(null);
    System.out.println(schema);

    // test 1st level schema;
    ColumnSchema f1 = schema.getColumn(0);
    Assert.assertEquals("r1", f1.name);
    Assert.assertEquals(ColumnType.RECORD, f1.type);

    ColumnSchema f2 = schema.getColumn(1);
    Assert.assertEquals("r2", f2.name);
    Assert.assertEquals(ColumnType.RECORD, f2.type);

    // test 2nd level schema;
    Schema f1Schema = f1.schema;
    ColumnSchema f11 = f1Schema.getColumn(0);
    Assert.assertEquals("f1", f11.name);
    Assert.assertEquals(ColumnType.INT, f11.type);
    ColumnSchema f12 = f1Schema.getColumn(1);
    Assert.assertEquals("f2", f12.name);
    Assert.assertEquals(ColumnType.INT, f12.type);

    Schema f2Schema = f2.schema;
    ColumnSchema f21 = f2Schema.getColumn(0);
    Assert.assertEquals("r3", f21.name);
    Assert.assertEquals(ColumnType.RECORD, f21.type);

    // test 3rd level schema;
    Schema f21Schema = f21.schema;
    ColumnSchema f211 = f21Schema.getColumn(0);
    Assert.assertEquals("f3", f211.name);
    Assert.assertEquals(ColumnType.FLOAT, f211.type);
    ColumnSchema f212 = f21Schema.getColumn(1);
    Assert.assertEquals("f4", f212.name);
    Assert.assertEquals(ColumnType.BYTES, f212.type);
  }
View Full Code Here

    pathTable1 = new Path(pathWorking, "1");
    System.out.println("pathTable1 =" + pathTable1);

    BasicTable.Writer writer = new BasicTable.Writer(pathTable1, STR_SCHEMA1,
        STR_STORAGE1, false, conf);
    Schema schema = writer.getSchema();
    Tuple tuple = TypesUtils.createTuple(schema);

    final int numsBatch = 10;
    final int numsInserters = 2;
    TableInserter[] inserters = new TableInserter[numsInserters];
View Full Code Here

    path = fs.getWorkingDirectory();
    System.out.println("path =" + path);

    BasicTable.Writer writer = new BasicTable.Writer(path, STR_SCHEMA,
        STR_STORAGE, false, conf);
    Schema schema = writer.getSchema();

    BasicTable.Writer writer1 = new BasicTable.Writer(path, conf);
    int part = 0;
    TableInserter inserter = writer1.getInserter("part" + part, true);
View Full Code Here

    BasicTable.drop(pathTable, conf);

    System.out.println("table path=" + pathTable);
    BasicTable.Writer writer = new BasicTable.Writer(pathTable,
        "c:collection(a:double, b:float, c:bytes)", "[c]", false, conf);
    Schema schema = writer.getSchema();
    Tuple tuple = TypesUtils.createTuple(schema);

    final int numsBatch = 10;
    final int numsInserters = 2;
    TableInserter[] inserters = new TableInserter[numsInserters];
    for (int i = 0; i < numsInserters; i++) {
      inserters[i] = writer.getInserter("ins" + i, false);
    }

    for (int b = 0; b < numsBatch; b++) {
      for (int i = 0; i < numsInserters; i++) {
        TypesUtils.resetTuple(tuple);

        DataBag bagColl = TypesUtils.createBag();
        Schema schColl = schema.getColumn(0).getSchema();
        Tuple tupColl1 = TypesUtils.createTuple(schColl);
        Tuple tupColl2 = TypesUtils.createTuple(schColl);
        byte[] abs1 = new byte[3];
        byte[] abs2 = new byte[4];
        tupColl1.set(0, 3.1415926);
View Full Code Here

    Path pathWorking = fs.getWorkingDirectory();
    pathTable = new Path(pathWorking, "TestMapTableLoader");

    BasicTable.Writer writer = new BasicTable.Writer(pathTable,
        "m1:map(string)", "[m1#{a}]", false, conf);
    Schema schema = writer.getSchema();
    Tuple tuple = TypesUtils.createTuple(schema);

    final int numsBatch = 10;
    final int numsInserters = 2;
    TableInserter[] inserters = new TableInserter[numsInserters];
View Full Code Here

    BasicTable.Writer writer = new BasicTable.Writer(path, STR_SCHEMA,
        STR_STORAGE, false, conf);
    writer.finish();

    Schema schema = writer.getSchema();
    Tuple tuple = TypesUtils.createTuple(schema);
    BasicTable.Writer writer1 = new BasicTable.Writer(path, conf);
    int part = 0;
    TableInserter inserter = writer1.getInserter("part" + part, true);
    TypesUtils.resetTuple(tuple);

    Tuple tupRecord1;
    try {
      tupRecord1 = TypesUtils.createTuple(schema.getColumnSchema("r1")
          .getSchema());
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }

    Tuple tupRecord2;
    try {
      tupRecord2 = TypesUtils.createTuple(schema.getColumnSchema("r2")
          .getSchema());
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }

    Tuple tupRecord3;
    try {
      tupRecord3 = TypesUtils.createTuple(new Schema("f3:float, f4"));
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }

    // row 1
    tuple.set(0, true); // bool
    tuple.set(1, 1); // int
    tuple.set(2, 1001L); // long
    tuple.set(3, 1.1); // float
    tuple.set(4, "hello world 1"); // string
    tuple.set(5, new DataByteArray("hello byte 1")); // byte

    // r1:record(f1:int, f2:long
    tupRecord1.set(0, 1);
    tupRecord1.set(1, 1001L);
    tuple.set(6, tupRecord1);

    // r2:record(r3:record(f3:float, f4))
    tupRecord2.set(0, tupRecord3);
    tupRecord3.set(0, 1.3);
    tupRecord3.set(1, new DataByteArray("r3 row 1 byte array "));
    tuple.set(7, tupRecord2);

    // m1:map(string)
    Map<String, String> m1 = new HashMap<String, String>();
    m1.put("a", "A");
    m1.put("b", "B");
    m1.put("c", "C");
    tuple.set(8, m1);

    // m2:map(map(int))
    HashMap<String, Map> m2 = new HashMap<String, Map>();
    Map<String, Integer> m3 = new HashMap<String, Integer>();
    m3.put("m311", 311);
    m3.put("m321", 321);
    m3.put("m331", 331);
    Map<String, Integer> m4 = new HashMap<String, Integer>();
    m4.put("m411", 411);
    m4.put("m421", 421);
    m4.put("m431", 431);
    m2.put("x", m3);
    m2.put("y", m4);
    tuple.set(9, m2);

    // c:collection(f13:double, f14:float, f15:bytes)
    DataBag bagColl = TypesUtils.createBag();
    Schema schColl = schema.getColumn(10).getSchema();
    Tuple tupColl1 = TypesUtils.createTuple(schColl);
    Tuple tupColl2 = TypesUtils.createTuple(schColl);
    byte[] abs1 = new byte[3];
    byte[] abs2 = new byte[4];
    tupColl1.set(0, 3.1415926);
View Full Code Here

    // drop any previous tables
    BasicTable.drop(pathTable, conf);

    BasicTable.Writer writer = new BasicTable.Writer(pathTable,
        "c:collection(a:double, b:float, c:bytes)", "[c]", false, conf);
    Schema schema = writer.getSchema();
    Tuple tuple = TypesUtils.createTuple(schema);

    final int numsBatch = 10;
    final int numsInserters = 2;
    TableInserter[] inserters = new TableInserter[numsInserters];
    for (int i = 0; i < numsInserters; i++) {
      inserters[i] = writer.getInserter("ins" + i, false);
    }

    for (int b = 0; b < numsBatch; b++) {
      for (int i = 0; i < numsInserters; i++) {
        TypesUtils.resetTuple(tuple);

        DataBag bagColl = TypesUtils.createBag();
        Schema schColl = schema.getColumn(0).getSchema();
        Tuple tupColl1 = TypesUtils.createTuple(schColl);
        Tuple tupColl2 = TypesUtils.createTuple(schColl);
        byte[] abs1 = new byte[3];
        byte[] abs2 = new byte[4];
        tupColl1.set(0, 3.1415926);
View Full Code Here

    System.out.println("path =" + path);

    BasicTable.Writer writer = new BasicTable.Writer(path, STR_SCHEMA,
        STR_STORAGE, false, conf);
    writer.finish();
    Schema schema = writer.getSchema();
    Tuple tuple = TypesUtils.createTuple(schema);
    BasicTable.Writer writer1 = new BasicTable.Writer(path, conf);
    int part = 0;
    TableInserter inserter = writer1.getInserter("part" + part, true);
    TypesUtils.resetTuple(tuple);

    Tuple record1;
    try {
      record1 = TypesUtils.createTuple(new Schema("f1:int, f2:string"));
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }

    Tuple record2;
    try {
      record2 = TypesUtils.createTuple(new Schema("f1:int, f2:string"));
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }

    Tuple record3;
    try {
      record3 = TypesUtils.createTuple(new Schema("f1:int, f2:string"));
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.zebra.types.Schema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.