@Test public void testDeserialize() throws Exception { csv.initialize(null, props); Text in = new Text("hello,\"yes, okay\",1,char"); List<Object> row = (List<Object>) csv.deserialize(in); Assert.assertEquals("hello", row.get(0)); Assert.assertEquals("yes, okay", row.get(1).toString()); Assert.assertEquals(1, row.get(2)); Assert.assertEquals("char ", row.get(3).toString()); in = new Text("hello,\"NULL\",1,char"); row = (List<Object>) csv.deserialize(in); Assert.assertEquals("hello", row.get(0)); Assert.assertEquals(null, row.get(1)); Assert.assertEquals(1, row.get(2)); Assert.assertEquals("char ", row.get(3).toString()); in = new Text("hello,\"yes, okay\",NULL,NULL"); row = (List<Object>) csv.deserialize(in); Assert.assertEquals("hello", row.get(0)); Assert.assertEquals("yes, okay", row.get(1).toString()); Assert.assertEquals(null, row.get(2)); Assert.assertEquals(null, row.get(3)); props.put(serdeConstants.LIST_COLUMNS, "a,b,c,d,e,f,g"); props.put(serdeConstants.LIST_COLUMN_TYPES, "string,varchar(20),int,char(10),array<int>,map<int,string>,struct<a:int,b:map<int,string>>"); csv.initialize(null, props); in = new Text("\"hello\",\"yes, okay\",\"1\"," + "\"char\",\"1,NULL,3\",\"5=five,NULL=six,7=NULL\",\"8:5=five,NULL=six,7=NULL\""); row = (List<Object>) csv.deserialize(in); Assert.assertEquals(row.size(), 7); Assert.assertEquals(row.get(0), "hello"); Assert.assertEquals(row.get(1).toString(), "yes, okay"); Assert.assertEquals(row.get(2), 1); Assert.assertEquals(row.get(3).toString(), "char "); Assert.assertTrue(row.get(4) instanceof List); List<Object> array = (List<Object>) row.get(4); Assert.assertEquals(array.size(), 3); Assert.assertEquals(array.get(0), 1); Assert.assertEquals(array.get(1), null); Assert.assertEquals(array.get(2), 3); Assert.assertTrue(row.get(5) instanceof Map); Map<Object, Object> map = (Map<Object, Object>) row.get(5); Assert.assertEquals(map.size(), 3); Assert.assertEquals(map.get(5), "five"); Assert.assertEquals(map.get(null), "six"); Assert.assertNull(map.get(7)); List<Object> struct = (List<Object>) row.get(6); Assert.assertEquals(struct.size(), 2); Assert.assertEquals(struct.get(0), 8); Assert.assertEquals(struct.get(1), map); }
@Override public Object deserialize(final Writable blob) throws SerDeException { Text rowText = (Text) blob; CSVReader csv = null; try { csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar, quoteChar, escapeChar); final String[] read = csv.readNext(); for (int i = 0; i < numCols; i++) { if (read != null && i < read.length && !read[i].equals(nullString)) { row.set(i, getColumnObject(read[i], columnTypes.get(i))); } else { row.set(i, null); } } return row; } catch (final Exception e) { throw new SerDeException(e); } finally { if (csv != null) { try { csv.close(); } catch (final Exception e) { } } } }
CSVSerde extends AbstractSerDe { @Override public Object deserialize(final Writable blob) throws SerDeException { Text rowText = (Text) blob; CSVReader csv = null; try { csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar, quoteChar, escapeChar); final String[] read = csv.readNext(); for (int i = 0; i < numCols; i++) { if (read != null && i < read.length && !read[i].equals(nullString)) { row.set(i, getColumnObject(read[i], columnTypes.get(i))); } else { row.set(i, null); } } return row; } catch (final Exception e) { throw new SerDeException(e); } finally { if (csv != null) { try { csv.close(); } catch (final Exception e) { } } } } }
CSVSerde extends AbstractSerDe { @Override public Object deserialize(final Writable blob) throws SerDeException { Text rowText = (Text) blob; CSVReader csv = null; try { csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar, quoteChar, escapeChar); final String[] read = csv.readNext(); for (int i = 0; i < numCols; i++) { if (read != null && i < read.length && !read[i].equals(nullString)) { row.set(i, getColumnObject(read[i], columnTypes.get(i))); } else { row.set(i, null); } } return row; } catch (final Exception e) { throw new SerDeException(e); } finally { if (csv != null) { try { csv.close(); } catch (final Exception e) { } } } }  }
CSVSerde extends AbstractSerDe { @Override public Object deserialize(final Writable blob) throws SerDeException { Text rowText = (Text) blob; CSVReader csv = null; try { csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar, quoteChar, escapeChar); final String[] read = csv.readNext(); for (int i = 0; i < numCols; i++) { if (read != null && i < read.length && !read[i].equals(nullString)) { row.set(i, getColumnObject(read[i], columnTypes.get(i))); } else { row.set(i, null); } } return row; } catch (final Exception e) { throw new SerDeException(e); } finally { if (csv != null) { try { csv.close(); } catch (final Exception e) { } } } }  @Override void initialize(final Configuration conf, final Properties tbl); @Override Writable serialize(Object obj, ObjectInspector objInspector); @Override Object deserialize(final Writable blob); @Override ObjectInspector getObjectInspector(); @Override Class<? extends Writable> getSerializedClass(); @Override SerDeStats getSerDeStats(); }
CSVSerde extends AbstractSerDe { @Override public Object deserialize(final Writable blob) throws SerDeException { Text rowText = (Text) blob; CSVReader csv = null; try { csv = newReader(new CharArrayReader(rowText.toString().toCharArray()), separatorChar, quoteChar, escapeChar); final String[] read = csv.readNext(); for (int i = 0; i < numCols; i++) { if (read != null && i < read.length && !read[i].equals(nullString)) { row.set(i, getColumnObject(read[i], columnTypes.get(i))); } else { row.set(i, null); } } return row; } catch (final Exception e) { throw new SerDeException(e); } finally { if (csv != null) { try { csv.close(); } catch (final Exception e) { } } } }  @Override void initialize(final Configuration conf, final Properties tbl); @Override Writable serialize(Object obj, ObjectInspector objInspector); @Override Object deserialize(final Writable blob); @Override ObjectInspector getObjectInspector(); @Override Class<? extends Writable> getSerializedClass(); @Override SerDeStats getSerDeStats(); static final String DEFAULT_NULL_FORMAT; static final char DEFAULT_COLLECTION_SEPERATOR; static final char DEFAULT_STRUCT_FIELD_SEPERATOR; static final char DEFAULT_UNION_TAG_FIELD_SEPERATOR; static final char DEFAULT_MAP_KEY_VALUE_SEPERATOR; }