Package org.apache.tajo.storage

Examples of org.apache.tajo.storage.VTuple


    for (Column col : target.getColumns()) {
      Preconditions.checkState(statSet.containsKey(col),
          "ERROR: Invalid Column Stats (column stats: " + colStats + ", there exists not target " + col);
    }

    Tuple startTuple = new VTuple(target.size());
    Tuple endTuple = new VTuple(target.size());
    int i = 0;

    // In outer join, empty table could be searched.
    // As a result, min value and max value would be null.
    // So, we should put NullDatum for this case.
    for (Column col : target.getColumns()) {
      if (sortSpecs[i].isAscending()) {
        if (statSet.get(col).getMinValue() != null)
          startTuple.put(i, statSet.get(col).getMinValue());
        else
          startTuple.put(i, DatumFactory.createNullDatum());

        if (statSet.get(col).getMaxValue() != null)
          endTuple.put(i, statSet.get(col).getMaxValue());
        else
          endTuple.put(i, DatumFactory.createNullDatum());
      } else {
        if (statSet.get(col).getMaxValue() != null)
          startTuple.put(i, statSet.get(col).getMaxValue());
        else
          startTuple.put(i, DatumFactory.createNullDatum());

        if (statSet.get(col).getMinValue() != null)
          endTuple.put(i, statSet.get(col).getMinValue());
        else
          endTuple.put(i, DatumFactory.createNullDatum());
      }
      i++;
    }
    return new TupleRange(sortSpecs, startTuple, endTuple);
  }
View Full Code Here


   *
   * @param size The number of columns of a creating tuple
   * @return The created tuple filled with NULL values
   */
  public static Tuple createNullPaddedTuple(int size){
    VTuple aTuple = new VTuple(size);
    int i;
    for(i = 0; i < size; i++){
      aTuple.put(i, DatumFactory.createNullDatum());
    }
    return aTuple;
  }
View Full Code Here

    // true means this is a file.
    if (beNullIfFile && partitionColumnSchema.size() < columnValues.length) {
      return null;
    }

    Tuple tuple = new VTuple(partitionColumnSchema.size());
    int i = 0;
    for (; i < columnValues.length && i < partitionColumnSchema.size(); i++) {
      String [] parts = columnValues[i].split("=");
      if (parts.length != 2) {
        return null;
      }
      int columnId = partitionColumnSchema.getColumnIdByName(parts[0]);
      Column keyColumn = partitionColumnSchema.getColumn(columnId);
      tuple.put(columnId, DatumFactory.createFromString(keyColumn.getDataType(), parts[1]));
    }
    for (; i < partitionColumnSchema.size(); i++) {
      tuple.put(i, NullDatum.get());
    }
    return tuple;
  }
View Full Code Here

    for (int i = 0; i < 100; i++) {
      Datum[] datums = new Datum[5];
      for (int j = 0; j < 5; j++) {
        datums[j] = new TextDatum(i + "_" + j);
      }
      Tuple tuple = new VTuple(datums);
      tupleData.add(tuple);
    }

    ExecutionBlockId ebId = QueryIdFactory.newExecutionBlockId(
        QueryIdFactory.newQueryId(System.currentTimeMillis(), 0));
View Full Code Here

    FieldEval f4 = new FieldEval("people.fid2", CatalogUtil.newSimpleDataType(Type.INT4));

    EvalNode joinQual = new BinaryEval(EvalType.EQUAL, f1, f2);
    TupleComparator [] comparators = PlannerUtil.getComparatorsFromJoinQual(joinQual, outerSchema, innerSchema);

    Tuple t1 = new VTuple(2);
    t1.put(0, DatumFactory.createInt4(1));
    t1.put(1, DatumFactory.createInt4(2));

    Tuple t2 = new VTuple(2);
    t2.put(0, DatumFactory.createInt4(2));
    t2.put(1, DatumFactory.createInt4(3));

    TupleComparator outerComparator = comparators[0];
    assertTrue(outerComparator.compare(t1, t2) < 0);
    assertTrue(outerComparator.compare(t2, t1) > 0);
View Full Code Here

  @Test
  public void testAll() throws Exception {
    Path file = createTmpFile();
    Schema schema = createAllTypesSchema();
    Tuple tuple = new VTuple(schema.size());
    tuple.put(0, DatumFactory.createBool(true));
    tuple.put(1, DatumFactory.createBit((byte)128));
    tuple.put(2, DatumFactory.createChar('t'));
    tuple.put(3, DatumFactory.createInt2((short)2048));
    tuple.put(4, DatumFactory.createInt4(4096));
    tuple.put(5, DatumFactory.createInt8(8192L));
    tuple.put(6, DatumFactory.createFloat4(0.2f));
    tuple.put(7, DatumFactory.createFloat8(4.1));
    tuple.put(8, DatumFactory.createText(HELLO));
    tuple.put(9, DatumFactory.createBlob(HELLO.getBytes(Charsets.UTF_8)));
    tuple.put(10, NullDatum.get());

    TajoParquetWriter writer = new TajoParquetWriter(file, schema);
    writer.write(tuple);
    writer.close();

    TajoParquetReader reader = new TajoParquetReader(file, schema);
    tuple = reader.read();

    assertNotNull(tuple);
    assertEquals(true, tuple.getBool(0));
    assertEquals((byte)128, tuple.getByte(1));
    assertTrue(String.valueOf('t').equals(String.valueOf(tuple.getChar(2))));
    assertEquals((short)2048, tuple.getInt2(3));
    assertEquals(4096, tuple.getInt4(4));
    assertEquals(8192L, tuple.getInt8(5));
    assertEquals(new Float(0.2f), new Float(tuple.getFloat4(6)));
    assertEquals(new Double(4.1), new Double(tuple.getFloat8(7)));
    assertTrue(HELLO.equals(tuple.getText(8)));
    assertArrayEquals(HELLO.getBytes(Charsets.UTF_8), tuple.getBytes(9));
    assertEquals(NullDatum.get(), tuple.get(10));
  }
View Full Code Here

  }

  public void testEval(Schema schema, String tableName, String csvTuple, String query, String [] expected,
                       char delimiter, boolean condition) throws IOException {
    LazyTuple lazyTuple;
    VTuple vtuple  = null;
    String qualifiedTableName =
        CatalogUtil.buildFQName(DEFAULT_DATABASE_NAME,
            tableName != null ? CatalogUtil.normalizeIdentifier(tableName) : null);
    Schema inputSchema = null;
    if (schema != null) {
      inputSchema = SchemaUtil.clone(schema);
      inputSchema.setQualifier(qualifiedTableName);

      int targetIdx [] = new int[inputSchema.size()];
      for (int i = 0; i < targetIdx.length; i++) {
        targetIdx[i] = i;
      }

      lazyTuple =
          new LazyTuple(inputSchema, Bytes.splitPreserveAllTokens(csvTuple.getBytes(), delimiter, targetIdx),0);
      vtuple = new VTuple(inputSchema.size());
      for (int i = 0; i < inputSchema.size(); i++) {
        // If null value occurs, null datum is manually inserted to an input tuple.
        if (lazyTuple.get(i) instanceof TextDatum && lazyTuple.get(i).asChars().equals("")) {
          vtuple.put(i, NullDatum.get());
        } else {
          vtuple.put(i, lazyTuple.get(i));
        }
      }
      cat.createTable(new TableDesc(qualifiedTableName, inputSchema,
          CatalogProtos.StoreType.CSV, new Options(), CommonTestingUtil.getTestDir()));
    }

    Target [] targets;

    try {
      targets = getRawTargets(query, condition);

      Tuple outTuple = new VTuple(targets.length);
      for (int i = 0; i < targets.length; i++) {
        EvalNode eval = targets[i].getEvalTree();
        outTuple.put(i, eval.eval(inputSchema, vtuple));
      }

      for (int i = 0; i < expected.length; i++) {
        assertEquals(query, expected[i], outTuple.get(i).asChars());
      }
    } catch (InvalidStatementException e) {
      assertFalse(e.getMessage(), true);
    } catch (PlanningException e) {
      // In failure test case, an exception must occur while executing query.
View Full Code Here

    schema1.addColumn("table1.id", INT4);
    schema1.addColumn("table1.score", INT4);
   
    BinaryEval expr = new BinaryEval(EvalType.PLUS, e1, e2);
    assertCloneEqual(expr);
    VTuple tuple = new VTuple(2);
    tuple.put(0, DatumFactory.createInt4(1)); // put 0th field
    tuple.put(1, DatumFactory.createInt4(99)); // put 0th field

    // the result of evaluation must be 100.
    assertEquals(expr.eval(schema1, tuple).asInt4(), 100);
  }
View Full Code Here

  public Tuple next() throws IOException {
    if (!dataFileReader.hasNext()) {
      return null;
    }

    Tuple tuple = new VTuple(schema.size());
    GenericRecord record = dataFileReader.next();
    for (int i = 0; i < projectionMap.length; ++i) {
      int columnIndex = projectionMap[i];
      Object value = record.get(columnIndex);
      if (value == null) {
        tuple.put(columnIndex, NullDatum.get());
        continue;
      }

      // Get Avro type.
      Schema.Field avroField = avroFields.get(columnIndex);
      Schema nonNullAvroSchema = getNonNull(avroField.schema());
      Schema.Type avroType = nonNullAvroSchema.getType();

      // Get Tajo type.
      Column column = schema.getColumn(columnIndex);
      DataType dataType = column.getDataType();
      TajoDataTypes.Type tajoType = dataType.getType();
      switch (avroType) {
        case NULL:
          tuple.put(columnIndex, NullDatum.get());
          break;
        case BOOLEAN:
          tuple.put(columnIndex, DatumFactory.createBool((Boolean)value));
          break;
        case INT:
          tuple.put(columnIndex, convertInt(value, tajoType));
          break;
        case LONG:
          tuple.put(columnIndex, DatumFactory.createInt8((Long)value));
          break;
        case FLOAT:
          tuple.put(columnIndex, DatumFactory.createFloat4((Float)value));
          break;
        case DOUBLE:
          tuple.put(columnIndex, DatumFactory.createFloat8((Double)value));
          break;
        case BYTES:
          tuple.put(columnIndex, convertBytes(value, tajoType, dataType));
          break;
        case STRING:
          tuple.put(columnIndex, convertString(value, tajoType));
          break;
        case RECORD:
          throw new RuntimeException("Avro RECORD not supported.");
        case ENUM:
          throw new RuntimeException("Avro ENUM not supported.");
        case MAP:
          throw new RuntimeException("Avro MAP not supported.");
        case UNION:
          throw new RuntimeException("Avro UNION not supported.");
        case FIXED:
          tuple.put(columnIndex, new BlobDatum(((GenericFixed)value).bytes()));
          break;
        default:
          throw new RuntimeException("Unknown type.");
      }
    }
View Full Code Here

   * Called before processing fields. This method fills any fields that have
   * NULL values or have type NULL_TYPE with a NullDatum.
   */
  @Override
  public void start() {
    currentTuple = new VTuple(tupleSize);
  }
View Full Code Here

TOP

Related Classes of org.apache.tajo.storage.VTuple

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.