Package org.apache.hadoop.hive.common.type

Examples of org.apache.hadoop.hive.common.type.HiveVarchar


  @Test
  public void testVarCharScalarConcatCol() {

    // has nulls, not repeating
    VectorizedRowBatch batch = makeStringBatch();
    VarCharScalarConcatStringGroupCol expr = new VarCharScalarConcatStringGroupCol(new HiveVarchar(new String(red), 14), 0, 1);
    expr.evaluate(batch);
    BytesColumnVector outCol = (BytesColumnVector) batch.cols[1];

    int cmp = StringExpr.compare(redred, 0, redred.length, outCol.vector[0],
        outCol.start[0], outCol.length[0]);
View Full Code Here


      break;
    case VARCHAR: {
        BytesColumnVector bcv = (BytesColumnVector) batch.cols[offset + colIndex];
        if (writableCol != null) {
          bcv.isNull[rowIndex] = false;
          HiveVarchar colHiveVarchar = ((HiveVarcharWritable) writableCol).getHiveVarchar();
          byte[] bytes = colHiveVarchar.getValue().getBytes();

          // We assume the VARCHAR maximum length was enforced when the object was created.
          int length = bytes.length;

          int start = buffer.getLength();
View Full Code Here

      }

      @Override
      public Object initValue(Object ignored) {
        return ((SettableHiveVarcharObjectInspector) this.objectInspector)
            .create(new HiveVarchar(StringUtils.EMPTY, -1));
      }
    }.init(fieldObjInspector);
  }
View Full Code Here

  @Test
  @Concurrent(count=4)
  @Repeating(repetition=100)
  public void testStringLength() throws Exception {
    HiveVarcharWritable vc1 = new HiveVarcharWritable(new HiveVarchar("0123456789", 10));
    assertEquals(10, vc1.getCharacterLength());

    // Changing string value; getCharacterLength() should update accordingly
    vc1.set("012345678901234");
    assertEquals(15, vc1.getCharacterLength());

    vc1.set(new HiveVarcharWritable(new HiveVarchar("01234", -1)));
    assertEquals(5, vc1.getCharacterLength());

    vc1.set(new HiveVarchar("012345", -1));
    assertEquals(6, vc1.getCharacterLength());

    vc1.set("0123456", -1);
    assertEquals(7, vc1.getCharacterLength());

    vc1.set(new HiveVarcharWritable(new HiveVarchar("01234567", -1)), -1);
    assertEquals(8, vc1.getCharacterLength());

    // string length should work after enforceMaxLength()
    vc1.enforceMaxLength(3);
    assertEquals(3, vc1.getCharacterLength());

    // string length should work after readFields()
    ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
    HiveVarcharWritable vc2 = new HiveVarcharWritable(new HiveVarchar("abcdef", -1));
    vc2.write(new DataOutputStream(outputBytes));
    vc1.readFields(new DataInputStream(new ByteArrayInputStream(outputBytes.toByteArray())));
    assertEquals(6, vc1.getCharacterLength());
  }
View Full Code Here

  @Test
  @Concurrent(count=4)
  @Repeating(repetition=100)
  public void testEnforceLength() throws Exception {
    HiveVarcharWritable vc1 = new HiveVarcharWritable(new HiveVarchar("0123456789", 10));
    assertEquals(10, vc1.getCharacterLength());

    vc1.enforceMaxLength(20);
    assertEquals(10, vc1.getCharacterLength());
View Full Code Here

  @Test
  @Concurrent(count=4)
  @Repeating(repetition=100)
  public void testComparison() throws Exception {
    HiveVarcharWritable hc1 = new HiveVarcharWritable(new HiveVarchar("abcd", 20));
    HiveVarcharWritable hc2 = new HiveVarcharWritable(new HiveVarchar("abcd", 20));

    // Identical strings should be equal
    assertTrue(hc1.equals(hc2));
    assertTrue(hc2.equals(hc1));
    assertEquals(0, hc1.compareTo(hc2));
    assertEquals(0, hc2.compareTo(hc1));

    // Unequal strings
    hc2 = new HiveVarcharWritable(new HiveVarchar("abcde", 20));
    assertFalse(hc1.equals(hc2));
    assertFalse(hc2.equals(hc1));
    assertFalse(0 == hc1.compareTo(hc2));
    assertFalse(0 == hc2.compareTo(hc1));

    // Trailing spaces are significant
    hc2 = new HiveVarcharWritable(new HiveVarchar("abcd  ", 30));

    assertFalse(hc1.equals(hc2));
    assertFalse(hc2.equals(hc1));
    assertFalse(0 == hc1.compareTo(hc2));
    assertFalse(0 == hc2.compareTo(hc1));

    // Leading spaces are significant
    hc2 = new HiveVarcharWritable(new HiveVarchar("  abcd", 20));
    assertFalse(hc1.equals(hc2));
    assertFalse(hc2.equals(hc1));
    assertFalse(0 == hc1.compareTo(hc2));
    assertFalse(0 == hc2.compareTo(hc1));
  }
View Full Code Here

  @Test
  @Concurrent(count=4)
  @Repeating(repetition=100)
  public void testStringValue() throws Exception {
    HiveVarcharWritable vc1 = new HiveVarcharWritable(new HiveVarchar("abcde", 20));
    assertEquals("abcde", vc1.toString());
    assertEquals("abcde", vc1.getHiveVarchar().toString());
  }
View Full Code Here

    assertTrue(ve instanceof FilterCharColumnNotBetween);

    // VARCHAR tests
    VarcharTypeInfo varcharTypeInfo = new VarcharTypeInfo(10);
    col1Expr = new  ExprNodeColumnDesc(varcharTypeInfo, "col1", "table", false);
    constDesc = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Alpha", 10));
    constDesc2 = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Bravo", 10));

    // VARCHAR BETWEEN
    udf = new GenericUDFBetween();
    children1 = new ArrayList<ExprNodeDesc>();
    children1.add(new ExprNodeConstantDesc(new Boolean(false))); // no NOT keyword
View Full Code Here

    ve = vc.getVectorExpression(exprDesc);
    assertTrue(ve instanceof IfExprCharScalarStringGroupColumn);
    // test for VARCHAR type
    VarcharTypeInfo varcharTypeInfo = new VarcharTypeInfo(10);
    constDesc2 = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Alpha", 10));
    constDesc3 = new ExprNodeConstantDesc(varcharTypeInfo, new HiveVarchar("Bravo", 10));
    col2Expr = new  ExprNodeColumnDesc(varcharTypeInfo, "col2", "table", false);
    col3Expr = new  ExprNodeColumnDesc(varcharTypeInfo, "col3", "table", false);

    // column/column
    children1.set(1, col2Expr);
View Full Code Here

  private Writable getWritableValue(TypeInfo ti, byte[] value) {
    if (ti.equals(TypeInfoFactory.stringTypeInfo)) {
      return new Text(value);
    } else if (ti.equals(TypeInfoFactory.varcharTypeInfo)) {
      return new HiveVarcharWritable(
          new HiveVarchar(new Text(value).toString(), -1));
    } else if (ti.equals(TypeInfoFactory.binaryTypeInfo)) {
      return new BytesWritable(value);
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hive.common.type.HiveVarchar

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.