use of java.io.UnsupportedEncodingException in project hive by apache.
the class TestRCFile method setup.
@Before
public void setup() throws Exception {
conf = new Configuration();
ColumnProjectionUtils.setReadAllColumns(conf);
fs = FileSystem.getLocal(conf);
dir = new Path(System.getProperty("test.tmp.dir", ".") + "/mapred");
file = new Path(dir, "test_rcfile");
cleanup();
// the SerDe part is from TestLazySimpleSerDe
serDe = new ColumnarSerDe();
// Create the SerDe
tbl = createProperties();
SerDeUtils.initializeSerDe(serDe, conf, tbl, null);
try {
bytesArray = new byte[][] { "123".getBytes("UTF-8"), "456".getBytes("UTF-8"), "789".getBytes("UTF-8"), "1000".getBytes("UTF-8"), "5.3".getBytes("UTF-8"), "hive and hadoop".getBytes("UTF-8"), new byte[0], "NULL".getBytes("UTF-8") };
s = new BytesRefArrayWritable(bytesArray.length);
s.set(0, new BytesRefWritable("123".getBytes("UTF-8")));
s.set(1, new BytesRefWritable("456".getBytes("UTF-8")));
s.set(2, new BytesRefWritable("789".getBytes("UTF-8")));
s.set(3, new BytesRefWritable("1000".getBytes("UTF-8")));
s.set(4, new BytesRefWritable("5.3".getBytes("UTF-8")));
s.set(5, new BytesRefWritable("hive and hadoop".getBytes("UTF-8")));
s.set(6, new BytesRefWritable("NULL".getBytes("UTF-8")));
s.set(7, new BytesRefWritable("NULL".getBytes("UTF-8")));
// partial test init
patialS.set(0, new BytesRefWritable("NULL".getBytes("UTF-8")));
patialS.set(1, new BytesRefWritable("NULL".getBytes("UTF-8")));
patialS.set(2, new BytesRefWritable("789".getBytes("UTF-8")));
patialS.set(3, new BytesRefWritable("1000".getBytes("UTF-8")));
patialS.set(4, new BytesRefWritable("NULL".getBytes("UTF-8")));
// LazyString has no so-called NULL sequence. The value is empty string if not.
patialS.set(5, new BytesRefWritable("".getBytes("UTF-8")));
patialS.set(6, new BytesRefWritable("NULL".getBytes("UTF-8")));
// LazyString has no so-called NULL sequence. The value is empty string if not.
patialS.set(7, new BytesRefWritable("".getBytes("UTF-8")));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
use of java.io.UnsupportedEncodingException in project hive by apache.
the class TestConvertAstToSearchArg method getFuncDesc.
private ExprNodeGenericFuncDesc getFuncDesc(String xmlSerialized) {
byte[] bytes;
try {
bytes = xmlSerialized.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException("UTF-8 support required", ex);
}
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
XMLDecoder decoder = new XMLDecoder(bais, null, null);
try {
return (ExprNodeGenericFuncDesc) decoder.readObject();
} finally {
decoder.close();
}
}
use of java.io.UnsupportedEncodingException in project hive by apache.
the class TBinarySortableProtocol method readString.
@Override
public String readString() throws TException {
if (readIsNull()) {
return null;
}
int i = 0;
while (true) {
readRawAll(bin, 0, 1);
if (bin[0] == 0) {
// End of string.
break;
}
if (bin[0] == 1) {
// Escaped byte, unescape it.
readRawAll(bin, 0, 1);
assert (bin[0] == 1 || bin[0] == 2);
bin[0] = (byte) (bin[0] - 1);
}
if (i == stringBytes.length) {
stringBytes = Arrays.copyOf(stringBytes, stringBytes.length * 2);
}
stringBytes[i] = bin[0];
i++;
}
try {
String r = new String(stringBytes, 0, i, "UTF-8");
return r;
} catch (UnsupportedEncodingException uex) {
throw new TException("JVM DOES NOT SUPPORT UTF-8: ", uex);
}
}
use of java.io.UnsupportedEncodingException in project hive by apache.
the class TestVectorStringExpressions method testLoadBytesColumnVectorByRef.
@Test
public // set values by reference, copy the data out, and verify equality
void testLoadBytesColumnVectorByRef() {
BytesColumnVector bcv = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
String s = "red";
byte[] b = null;
try {
b = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
for (int i = 0; i != VectorizedRowBatch.DEFAULT_SIZE; i++) {
bcv.setRef(i, b, 0, b.length);
}
// verify
byte[] v = new byte[b.length];
for (int i = 0; i != VectorizedRowBatch.DEFAULT_SIZE; i++) {
Assert.assertTrue(bcv.length[i] == b.length);
System.arraycopy(bcv.vector[i], bcv.start[i], v, 0, b.length);
Assert.assertTrue(Arrays.equals(b, v));
}
}
use of java.io.UnsupportedEncodingException in project hive by apache.
the class TestVectorStringExpressions method testLoadBytesColumnVectorByValueLargeData.
@Test
public // the buffer to expand.
void testLoadBytesColumnVectorByValueLargeData() {
BytesColumnVector bcv = new BytesColumnVector(VectorizedRowBatch.DEFAULT_SIZE);
// initialize with estimated element size 10
bcv.initBuffer(10);
// Record initial buffer size
int initialBufferSize = bcv.bufferSize();
String s = "0123456789";
while (s.length() < 500) {
s += s;
}
byte[] b = null;
try {
b = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
for (int i = 0; i != VectorizedRowBatch.DEFAULT_SIZE; i++) {
bcv.setVal(i, b, 0, b.length);
}
// Current buffer size should be larger than initial size
Assert.assertTrue(bcv.bufferSize() > initialBufferSize);
}
Aggregations