Examples of HiveVarchar


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

    }
    return getWritableWithParams((HiveVarchar)o);
  }

  private HiveVarchar getPrimitiveWithParams(HiveVarchar val) {
    HiveVarchar hv = new HiveVarchar(val, getMaxLength());
    return hv;
  }
View Full Code Here

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

    if (BaseCharUtils.doesPrimitiveMatchTypeParams(
        value, (VarcharTypeInfo)typeInfo)) {
      return o = value;
    } else {
      // Otherwise value may be too long, convert to appropriate value based on params
      return o = new HiveVarchar(value,  getMaxLength());
    }
  }
View Full Code Here

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

    }
  }

  @Override
  public Object set(Object o, String value) {
    return o = new HiveVarchar(value, getMaxLength());
  }
View Full Code Here

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

    return o = new HiveVarchar(value, getMaxLength());
  }

  @Override
  public Object create(HiveVarchar value) {
    HiveVarchar hc = new HiveVarchar(value, getMaxLength());
    return hc;
  }
View Full Code Here

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

  public HiveVarchar getPrimitiveJavaObject(Object o) {
    if (o == null) {
      return null;
    }

    HiveVarchar ret = ((LazyHiveVarchar) o).getWritableObject().getHiveVarchar();
    if (!BaseCharUtils.doesPrimitiveMatchTypeParams(
        ret, (VarcharTypeInfo)typeInfo)) {
      HiveVarchar newValue = new HiveVarchar(ret, ((VarcharTypeInfo)typeInfo).getLength());
      return newValue;
    }
    return ret;
  }
View Full Code Here

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

import org.apache.hadoop.hive.common.type.HiveVarchar;
import java.io.*;

public class TestHiveVarcharWritable extends TestCase {
  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

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

    vc1.readFields(new DataInputStream(new ByteArrayInputStream(outputBytes.toByteArray())));
    assertEquals(6, vc1.getCharacterLength());
  }

  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

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

    vc1.enforceMaxLength(8);
    assertEquals(8, vc1.getCharacterLength());
}

  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

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

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

  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

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

  @Test
  public void testVarchar() throws HiveException {
    GenericUDFFloor udf = new GenericUDFFloor();

    HiveVarchar vc = new HiveVarchar("32300.004747", 12);
    HiveVarcharWritable input = new HiveVarcharWritable(vc);
    VarcharTypeInfo inputTypeInfo = TypeInfoFactory.getVarcharTypeInfo(12);
    ObjectInspector[] inputOIs = {
        PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(inputTypeInfo),
    };
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.