Package org.apache.hadoop.zebra.types

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


  @Test
  public void testSchemaValid3() throws ParseException {
    String strSch = "m1:map(map(float)), m2:map(bool), f3";
    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("m1", f1.name);
    Assert.assertEquals(ColumnType.MAP, f1.type);

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

    ColumnSchema f3 = schema.getColumn(2);
    Assert.assertEquals("f3", f3.name);
    Assert.assertEquals(ColumnType.BYTES, f3.type);

    // test 2nd level schema;
    Schema f1Schema = f1.schema;
    ColumnSchema f11 = f1Schema.getColumn(0);
    Assert.assertEquals(ColumnType.MAP, f11.type);

    Schema f2Schema = f2.schema;
    ColumnSchema f21 = f2Schema.getColumn(0);
    Assert.assertEquals(ColumnType.BOOL, f21.type);

    // test 3rd level schema;
    Schema f11Schema = f11.schema;
    ColumnSchema f111 = f11Schema.getColumn(0);
    Assert.assertEquals(ColumnType.FLOAT, f111.type);
  }
View Full Code Here


  @Test
  public void testSchemaInvalid1() throws ParseException {
    try {
      String strSch = "m1:abc";
      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

  @Test
  public void testSchemaInvalid2() throws ParseException {
    try {
      String strSch = "m1:map(int";
      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

  @Test
  public void testSchemaInvalid3() throws ParseException {
    try {
      String strSch = "m1:map(int, f2:int";
      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

  @Test
  public void testSchemaInvalid4() throws ParseException {
    try {
      String strSch = "m1:map(m2:int)";
      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

  @Test
  public void testSchemaInvalid5() throws ParseException {
    try {
      String strSch = "m1:map(abc)";
      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

      @Override
      public void configure(JobConf job) {
        LOG.info("FreqWords.ReduceClass.configure");
        freqWords = new FreqWordCache(getFreqWordsCount(job));
        try {
          Schema outSchema = BasicTableOutputFormat.getSchema(job);
          outRow = TypesUtils.createTuple(outSchema);
          idxCount = outSchema.getColumnIndex("count");
        } catch (IOException e) {
          throw new RuntimeException("Schema parsing failed : "
              + e.getMessage());
        } catch (ParseException e) {
          throw new RuntimeException("Schema parsing failed : "
View Full Code Here

    @Override
    public void configure(JobConf job) {
      bytesKey = new BytesWritable();
      try {
        Schema outSchema = BasicTableOutputFormat.getSchema(job);
        tupleRow = TypesUtils.createTuple(outSchema);
      } catch (IOException e) {
        throw new RuntimeException(e);
      } catch (ParseException e) {
        throw new RuntimeException(e);
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);

    BasicTable.Writer writer1 = new BasicTable.Writer(pathTable1, conf);
    int part = 0;
    TableInserter inserter = writer1.getInserter("part" + part, true);

    TypesUtils.resetTuple(tuple);
    DataBag bag1 = TypesUtils.createBag();
    Schema schColl = schema.getColumn(0).getSchema();
    Tuple tupColl1 = TypesUtils.createTuple(schColl);
    Tuple tupColl2 = TypesUtils.createTuple(schColl);

    int row = 0;
    tupColl1.set(0, "1.1");
    tupColl1.set(1, "1.11");
    bag1.add(tupColl1);
    tupColl2.set(0, "1.111");
    tupColl2.set(1, "1.1111");
    bag1.add(tupColl2);
    tuple.set(0, bag1);

    Map<String, String> m1 = new HashMap<String, String>();
    m1.put("k1", "k11");
    m1.put("b", "b1");
    m1.put("c", "c1");
    tuple.set(1, m1);

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

    tupRecord1.set(0, "1");
    tupRecord1.set(1, "hello1");
    tuple.set(2, tupRecord1);
    tuple.set(3, "world1");

    inserter.insert(new BytesWritable(String.format("k%d%d", part + 1, row + 1)
        .getBytes()), tuple);

    // second row
    row++;
    TypesUtils.resetTuple(tuple);
    TypesUtils.resetTuple(tupRecord1);
    TypesUtils.resetTuple(tupColl1);
    TypesUtils.resetTuple(tupColl2);
    m1.clear();
    bag1.clear();

    row++;
    tupColl1.set(0, "2.2");
    tupColl1.set(1, "2.22");
    bag1.add(tupColl1);
    tupColl2.set(0, "2.222");
    tupColl2.set(1, "2.2222");
    bag1.add(tupColl2);
    tuple.set(0, bag1);

    m1.put("k2", "k22");
    m1.put("k3", "k32");
    m1.put("k1", "k12");
    m1.put("k4", "k42");
    tuple.set(1, m1);

    tupRecord1.set(0, "2");
    tupRecord1.set(1, "hello2");
    tuple.set(2, tupRecord1);
    tuple.set(3, "world2");

    inserter.insert(new BytesWritable(String.format("k%d%d", part + 1, row + 1)
        .getBytes()), tuple);
    inserter.close();
    writer1.finish();
    writer.close();

    /*
     * create 2nd basic table;
     */
    pathTable2 = new Path(pathWorking, "2");
    System.out.println("pathTable2 =" + pathTable2);

    BasicTable.Writer writer2 = new BasicTable.Writer(pathTable2, STR_SCHEMA2,
        STR_STORAGE2, false, conf);
    Schema schema2 = writer.getSchema();

    Tuple tuple2 = TypesUtils.createTuple(schema2);

    BasicTable.Writer writer22 = new BasicTable.Writer(pathTable2, conf);
    part = 0;
View Full Code Here

    @Override
    public void configure(JobConf job) {
      bytesKey = new BytesWritable();
      try {
        Schema outSchema = BasicTableOutputFormat.getSchema(job);
        tupleRow = TypesUtils.createTuple(outSchema);
      } catch (IOException e) {
        throw new RuntimeException(e);
      } catch (ParseException e) {
        throw new RuntimeException(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.