You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by "zengchuan (Commented) (JIRA)" <ji...@apache.org> on 2012/03/13 09:13:41 UTC

[jira] [Commented] (HIVE-1245) allow access to values stored as non-strings in HBase

    [ https://issues.apache.org/jira/browse/HIVE-1245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13228266#comment-13228266 ] 

zengchuan commented on HIVE-1245:
---------------------------------

I'm new to hbase and hive. I create a table in hbase and add data array into it.

    public static void createTable(String tablename) throws IOException{  
        HBaseAdmin admin = new HBaseAdmin(hbaseConfig);  
        if(admin.tableExists(tablename)){  
            System.out.println("table Exists!!!");  
        }else{  
            HTableDescriptor tableDesc = new HTableDescriptor(tablename);  
            tableDesc.addFamily(new HColumnDescriptor("dom"));  
            admin.createTable(tableDesc);  
        }  
    }

    public static void addData(String tablename) throws IOException{  
        HTable table=new HTable(hbaseConfig,tablename); 
        	Put put = new Put(Bytes.toBytes(String.valueOf(i)));
	        
	        List<String> a = new ArrayList<String>();
	        a.add("domain1");
	        a.add("domain2");
	        
	        Object obj = doType(hbaseConfig, a, List.class);
	        Writable w = new HbaseObjectWritable(obj);
	        byte[] depthMapByteArray = WritableUtils.toByteArray(w);
	        put.add(Bytes.toBytes("dom"),
		        	Bytes.toBytes("domain"),
		        	depthMapByteArray
		        	);

	       table.put(put);
    } 
    
    private static Object doType(Configuration conf, Object value,
    	      Class<?> clazz)
    	  throws IOException {
    	    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    	    DataOutputStream out = new DataOutputStream(byteStream);
    	    HbaseObjectWritable.writeObject(out, value, clazz, conf);
    	    out.close();
    	    ByteArrayInputStream bais =
    	      new ByteArrayInputStream(byteStream.toByteArray());
    	    DataInputStream dis = new DataInputStream(bais);
    	    Object product = HbaseObjectWritable.readObject(dis, conf);
    	    dis.close();
    	    return product;
    }

in hive i create a table

CREATE EXTERNAL TABLE hbase_table_2(row_key int, domain Array<String>) 
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,dom:domain")
TBLPROPERTIES("hbase.table.name" = "table2");

in hbase_table_2   domain Array<String> is not right. why?
                
> allow access to values stored as non-strings in HBase
> -----------------------------------------------------
>
>                 Key: HIVE-1245
>                 URL: https://issues.apache.org/jira/browse/HIVE-1245
>             Project: Hive
>          Issue Type: Improvement
>          Components: HBase Handler
>    Affects Versions: 0.6.0
>            Reporter: John Sichi
>            Assignee: Basab Maulik
>
> See  test case in
> http://mail-archives.apache.org/mod_mbox/hadoop-hive-user/201003.mbox/browser

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira