예제 #1
0
 /** ctor for full projection */
 public Projection(Schema s) {
   mProjection = s;
   if (s != null) {
     mNumColumns = s.getNumColumns();
     mProjStr = s.toString();
     mSchema = s;
   }
 }
예제 #2
0
 /** ctor for partial projection */
 public Projection(Schema s, String projection) throws ParseException {
   String[] colnames = projection.trim().split(Schema.COLUMN_DELIMITER);
   for (int nx = 0; nx < colnames.length; nx++) {
     colnames[nx] = colnames[nx].trim();
   }
   mKeys = new HashMap<Schema.ColumnSchema, HashSet<String>>();
   mProjection = s.getProjectionSchema(colnames, mKeys);
   mNumColumns = colnames.length;
   mProjStr = projection;
   mSchema = toSchema(projection);
 }
  public static void createFirstTable() throws IOException, ParseException {
    BasicTable.Writer writer = new BasicTable.Writer(pathTable1, STR_SCHEMA1, STR_STORAGE1, conf);
    Schema schema = writer.getSchema();
    // System.out.println("typeName" + schema.getColumn("a").type.pigDataType());
    Tuple tuple = TypesUtils.createTuple(schema);

    TableInserter[] inserters = new TableInserter[numsInserters];
    for (int i = 0; i < numsInserters; i++) {
      inserters[i] = writer.getInserter("ins" + i, false);
    }
    Tuple tupRecord1;
    try {
      tupRecord1 = TypesUtils.createTuple(schema.getColumnSchema("r1").getSchema());
    } catch (ParseException e) {
      e.printStackTrace();
      throw new IOException(e);
    }
    Map<String, String> m1 = new HashMap<String, String>();
    for (int b = 0; b < numsBatch; b++) {
      for (int i = 0; i < numsInserters; i++) {
        TypesUtils.resetTuple(tupRecord1);
        TypesUtils.resetTuple(tuple);
        m1.clear();

        try {
          // first row of the table , the biggest row
          if (i == 0 && b == 0) {
            tuple.set(0, 100);
            tuple.set(1, 100.1f);
            tuple.set(2, 100L);
            tuple.set(3, 50e+2);
            tuple.set(4, "something");
            tuple.set(5, new DataByteArray("something"));

          }
          // the middle + 1 row of the table, the smallest row
          else if (i == 0 && b == (numsBatch / 2)) {
            tuple.set(0, -100);
            tuple.set(1, -100.1f);
            tuple.set(2, -100L);
            tuple.set(3, -50e+2);
            tuple.set(4, "so");
            tuple.set(5, new DataByteArray("so"));

          } else {
            Float f = 1.1f;
            long l = 11;
            double d = 1.1;
            tuple.set(0, b);
            tuple.set(1, f);
            tuple.set(2, l);
            tuple.set(3, d);
            tuple.set(4, "some");
            tuple.set(5, new DataByteArray("some"));
          }

          // insert record
          tupRecord1.set(0, "" + b);
          tupRecord1.set(1, "" + b);
          tuple.set(6, tupRecord1);

          // insert map
          m1.put("a", "" + b);
          m1.put("b", "" + b);
          m1.put("c", "" + b);
          tuple.set(7, m1);

        } catch (ExecException e) {
          e.printStackTrace();
        }

        inserters[i].insert(new BytesWritable(("key_" + b).getBytes()), tuple);
      }
    }
    for (int i = 0; i < numsInserters; i++) {
      inserters[i].close();
    }
    writer.close();

    // check table is setup correctly
    String projection = new String("a,b,c,d,e,f,r1,m1");

    BasicTable.Reader reader = new BasicTable.Reader(pathTable1, conf);
    reader.setProjection(projection);
    List<RangeSplit> splits = reader.rangeSplit(1);
    TableScanner scanner = reader.getScanner(splits.get(0), true);
    BytesWritable key = new BytesWritable();
    Tuple RowValue = TypesUtils.createTuple(scanner.getSchema());

    scanner.getValue(RowValue);
    System.out.println("rowvalue size:" + RowValue.size());
    System.out.println("read a : " + RowValue.get(0).toString());
    System.out.println("read string: " + RowValue.get(1).toString());

    scanner.advance();
    scanner.getValue(RowValue);
    System.out.println("read float in 2nd row: " + RowValue.get(1).toString());
    System.out.println("done insert table");

    reader.close();
  }
예제 #4
0
 /** Get a particular projected column's schema */
 public Schema.ColumnSchema getColumnSchema(int i) {
   return mProjection.getColumn(i);
 }