Search in sources :

Example 11 with UnsupportedEncodingException

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);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ColumnarSerDe(org.apache.hadoop.hive.serde2.columnar.ColumnarSerDe) Configuration(org.apache.hadoop.conf.Configuration) BytesRefArrayWritable(org.apache.hadoop.hive.serde2.columnar.BytesRefArrayWritable) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BytesRefWritable(org.apache.hadoop.hive.serde2.columnar.BytesRefWritable) Before(org.junit.Before)

Example 12 with UnsupportedEncodingException

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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc)

Example 13 with UnsupportedEncodingException

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);
    }
}
Also used : TException(org.apache.thrift.TException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 14 with UnsupportedEncodingException

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));
    }
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Example 15 with UnsupportedEncodingException

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);
}
Also used : BytesColumnVector(org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Test(org.junit.Test)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1228 IOException (java.io.IOException)338 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)137 ArrayList (java.util.ArrayList)111 File (java.io.File)109 ByteArrayOutputStream (java.io.ByteArrayOutputStream)99 MessageDigest (java.security.MessageDigest)80 ByteArrayInputStream (java.io.ByteArrayInputStream)79 InputStream (java.io.InputStream)79 InputStreamReader (java.io.InputStreamReader)73 FileNotFoundException (java.io.FileNotFoundException)71 OutputStreamWriter (java.io.OutputStreamWriter)69 BufferedReader (java.io.BufferedReader)58 URL (java.net.URL)55 FileOutputStream (java.io.FileOutputStream)52 Map (java.util.Map)52 HashMap (java.util.HashMap)48 JSONException (org.json.JSONException)44 List (java.util.List)41 PrintStream (java.io.PrintStream)39