public Text getStrippedValue() { // A lot of these methods could be done more efficiently by operating on the Text value // directly, rather than converting to HiveChar. return new Text(getHiveChar().getStrippedValue()); }
private HiveChar getPrimitiveWithParams(HiveCharWritable val) { HiveChar hv = new HiveChar(); hv.setValue(val.getHiveChar(), getMaxLength()); return hv; }
public static HiveChar getHiveChar(Object o, PrimitiveObjectInspector oi) { if (o == null) { return null; } HiveChar result = null; switch (oi.getPrimitiveCategory()) { case CHAR: result = ((HiveCharObjectInspector) oi).getPrimitiveJavaObject(o); break; default: // No char length available, copy whole string value here. result = new HiveChar(); result.setValue(getString(o, oi)); break; } return result; }
@Test @Concurrent(count=4) @Repeating(repetition=100) public void testStringLength() { HiveChar hc = new HiveChar(); hc.setValue("0123456789", 5); assertEquals("01234", hc.toString()); hc.setValue("0123456789", 10); assertEquals("0123456789", hc.toString()); hc.setValue("0123456789", 15); assertEquals("0123456789 ", hc.toString()); }
HiveChar hc = new HiveChar(str, maxLength); return hc; case VARCHAR: HiveVarchar hvc = new HiveVarchar(str, maxLength); return hvc; case DATE: return new Date(DateWritable.daysToMillis((Integer)datum)); case TIMESTAMP: if (recordSchema.getType() != Type.LONG) { "Unexpected Avro schema for Date TypeInfo: " + recordSchema.getType()); return new Timestamp((Long)datum); default: return datum;
return new LongWritable(0); case TIMESTAMP: return new TimestampWritable(new Timestamp(0)); case DATE: return new DateWritable(new Date(0)); case FLOAT: return new FloatWritable(0); return new BytesWritable(ArrayUtils.EMPTY_BYTE_ARRAY); case STRING: return new Text(ArrayUtils.EMPTY_BYTE_ARRAY); case VARCHAR: return new HiveVarcharWritable(new HiveVarchar(StringUtils.EMPTY, -1)); case CHAR: return new HiveCharWritable(new HiveChar(StringUtils.EMPTY, -1)); case DECIMAL: return new HiveDecimalWritable();
private static final long DATE_DAYS = TimeUnit.MILLISECONDS.toDays(DATE_MILLIS_UTC); private static final String DATE_STRING = DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC().print(DATE_MILLIS_UTC); private static final Date SQL_DATE = new Date(UTC.getMillisKeepLocal(DateTimeZone.getDefault(), DATE_MILLIS_UTC)); private static final DecimalType DECIMAL_TYPE_PRECISION_38 = DecimalType.createDecimalType(38, 16); private static final HiveDecimal WRITE_DECIMAL_PRECISION_2 = HiveDecimal.create(new BigDecimal("-1.2")); private static final HiveDecimal WRITE_DECIMAL_PRECISION_4 = HiveDecimal.create(new BigDecimal("12.3")); private static final HiveDecimal WRITE_DECIMAL_PRECISION_8 = HiveDecimal.create(new BigDecimal("-1234.5678")); .add(new TestColumn("t_empty_string", javaStringObjectInspector, "", Slices.EMPTY_SLICE)) .add(new TestColumn("t_string", javaStringObjectInspector, "test", Slices.utf8Slice("test"))) .add(new TestColumn("t_empty_varchar", javaHiveVarcharObjectInspector, new HiveVarchar("", HiveVarchar.MAX_VARCHAR_LENGTH), Slices.EMPTY_SLICE)) .add(new TestColumn("t_varchar", javaHiveVarcharObjectInspector, new HiveVarchar("test", HiveVarchar.MAX_VARCHAR_LENGTH), Slices.utf8Slice("test"))) .add(new TestColumn("t_map_char", getStandardMapObjectInspector(CHAR_INSPECTOR_LENGTH_10, CHAR_INSPECTOR_LENGTH_10), ImmutableMap.of(new HiveChar("test", 10), new HiveChar("test", 10)), mapBlockOf(createCharType(10), createCharType(10), "test", "test"))) .add(new TestColumn("t_map_smallint", "t_array_char", getStandardListObjectInspector(CHAR_INSPECTOR_LENGTH_10), ImmutableList.of(new HiveChar("test", 10)), arrayBlockOf(createCharType(10), "test"))) .add(new TestColumn("t_array_date",
case BINARY: try { String t = Text.decode(s.getBytes(), 0, s.getBytes().length); return t.getBytes(); } catch (CharacterCodingException e) { return Date.valueOf(s); case TIMESTAMP: return Timestamp.valueOf(s); case DECIMAL: return HiveDecimal.create(s); case VARCHAR: return new HiveVarchar(s, ((BaseCharTypeInfo) mapKeyType).getLength()); case CHAR: return new HiveChar(s, ((BaseCharTypeInfo) mapKeyType).getLength()); default: throw new IOException(
value = ((HiveDecimal) value).bigDecimalValue(); } else if (value instanceof Decimal128) { value = ((Decimal128) value).toBigDecimal(); case CHAR: if (value instanceof HiveChar) { value = ((HiveChar) value).getValue(); case VARCHAR: if (value instanceof HiveVarchar) { value = ((HiveVarchar) value).getValue(); } else { c = Calendar.getInstance(); c.setTimeInMillis(((Timestamp)value).getTime());
return new BytesWritable(ArrayUtils.EMPTY_BYTE_ARRAY); case STRING: return new Text(ArrayUtils.EMPTY_BYTE_ARRAY); case VARCHAR: return new HiveVarcharWritable(new HiveVarchar(StringUtils.EMPTY, -1)); case CHAR: return new HiveCharWritable(new HiveChar(StringUtils.EMPTY, -1)); case DECIMAL: return new HiveDecimalWritable();
case CHAR: HiveChar ch = (HiveChar)fieldOI.getPrimitiveJavaObject(structFieldData); return ch.getStrippedValue(); case VARCHAR: HiveVarchar vc = (HiveVarchar)fieldOI.getPrimitiveJavaObject(structFieldData); return vc.getValue(); case DATE: Date date = ((DateObjectInspector)fieldOI).getPrimitiveJavaObject(structFieldData); return DateWritable.dateToDays(date); case TIMESTAMP: Timestamp timestamp = ((TimestampObjectInspector) fieldOI).getPrimitiveJavaObject(structFieldData); return timestamp.getTime(); case UNKNOWN: throw new AvroSerdeException("Received UNKNOWN primitive category.");
Text txt = new Text(); txt.set(b, 0, b.length); appendWithQuotes(sb, SerDeUtils.escapeString(txt.toString())); break; case DATE: case VARCHAR: { String s = SerDeUtils.escapeString( ((HiveVarcharObjectInspector) poi).getPrimitiveJavaObject(o).toString()); appendWithQuotes(sb, s); break; ((HiveCharObjectInspector) poi).getPrimitiveJavaObject(o).toString()); appendWithQuotes(sb, s); break;
if (lit instanceof HiveDecimal) { HiveDecimal dec = (HiveDecimal) lit; if (!dec.isLong()) { throw new ArithmeticException("Overflow"); return dec.longValue(); return ((HiveChar) lit).getPaddedValue(); } else if (lit instanceof String) { return lit; if (lit instanceof HiveDecimal) { dbl = ((HiveDecimal) lit).doubleValue(); } else { dbl = ((Number) lit); return Timestamp.valueOf(lit.toString()); case DATE: return Date.valueOf(lit.toString()); case DECIMAL: return new HiveDecimalWritable(lit.toString());
break; case DECIMAL: result = ((HiveDecimal)o).bigDecimalValue(); break; case CHAR: result = ((HiveChar)o).getValue(); break; case VARCHAR: result = ((HiveVarchar)o).getValue(); break; case DATE: result = new DateTime(d.getYear() + 1900, d.getMonth() + 1, d.getDate(), 0, 0);//uses local TZ break; case TIMESTAMP: result = new DateTime(((Timestamp)o).getTime());//uses local TZ break; default:
SearchArgumentFactory.newBuilder() .startAnd() .lessThan("x", PredicateLeaf.Type.DATE, Date.valueOf("2005-3-12")) .lessThanEquals("y", PredicateLeaf.Type.STRING, new HiveChar("hi", 10).toString()) .equals("z", PredicateLeaf.Type.DECIMAL, new HiveDecimalWritable("1.0")) .in("z", PredicateLeaf.Type.LONG, 1L, 2L, 3L) .nullSafeEquals("a", PredicateLeaf.Type.STRING, new HiveVarchar("stinger", 100).toString()) .end() .end()
dateWritable.set(date); ((LongColumnVector) batch.cols[projectionColumnNum]).vector[batchIndex] = dateWritable.getDays(); text.set(string); ((BytesColumnVector) batch.cols[projectionColumnNum]).setVal( batchIndex, text.getBytes(), 0, text.getLength()); byte[] bytes = hiveVarchar.getValue().getBytes(); ((BytesColumnVector) batch.cols[projectionColumnNum]).setVal( batchIndex, bytes, 0, bytes.length); byte[] bytes = hiveChar.getStrippedValue().getBytes(); ((BytesColumnVector) batch.cols[projectionColumnNum]).setVal( batchIndex, bytes, 0, bytes.length);
if (object instanceof Text) { Text text = (Text) object; string = text.toString(); } else if (object instanceof HiveChar) { HiveChar hiveChar = (HiveChar) object; string = hiveChar.getStrippedValue(); } else if (object instanceof HiveCharWritable) { HiveChar hiveChar = ((HiveCharWritable) object).getHiveChar(); string = hiveChar.getStrippedValue(); } else if (object instanceof HiveVarchar) { HiveVarchar hiveVarchar = (HiveVarchar) object; string = hiveVarchar.getValue(); } else if (object instanceof HiveVarcharWritable) { HiveVarchar hiveVarchar = ((HiveVarcharWritable) object).getHiveVarchar(); string = hiveVarchar.getValue(); } else { throw new RuntimeException("Unexpected");