Hi,

I'm using hive metastore api(org.apache.hive.hive-metastore-2.1.0.jar) to 
create table, when I do not specify the location uri, it works fine:


```

            HiveConf c = new HiveConf();
            c.set("hive.metastore.uris", "thrift://xx.xx.xx.xx:9083");
            HiveMetaStoreClient client = new HiveMetaStoreClient(c);
            Table table = new Table();
            table.setDbName("default");
            table.setTableName("dmx4");

            StorageDescriptor sd = new StorageDescriptor();
            List<FieldSchema> cols = new ArrayList<FieldSchema>();
            FieldSchema f1 = new FieldSchema("id", "int", "id");
            FieldSchema f2 = new FieldSchema("name", "string", "name");

            cols.add(f1);
            cols.add(f2);
            sd.setCols(cols);

            //sd.setLocation("hdfs://user/hive/warehouse/mx");

            sd.setInputFormat("org.apache.hadoop.mapred.TextInputFormat");
            
sd.setOutputFormat("org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat");

            SerDeInfo serdeInfo = new SerDeInfo();
            
serdeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
            Map<String, String> serdeParameters = new HashMap<String, String>();
            serdeParameters.put("field.delim", ",");
            serdeInfo.setParameters(serdeParameters);
            sd.setSerdeInfo(serdeInfo);
            table.setSd(sd);

            table.setOwner("root");
            table.setTableType("MANAGED_TABLE");
            client.createTable(table);

```


But it throws NPE when I specify the location uri:

```


            HiveConf c = new HiveConf();
            c.set("hive.metastore.uris", "thrift://xx.xx.xx.xx:9083");
            HiveMetaStoreClient client = new HiveMetaStoreClient(c);
            Table table = new Table();
            table.setDbName("default");
            table.setTableName("dmx4");

            StorageDescriptor sd = new StorageDescriptor();
            List<FieldSchema> cols = new ArrayList<FieldSchema>();
            FieldSchema f1 = new FieldSchema("id", "int", "id");
            FieldSchema f2 = new FieldSchema("name", "string", "name");

            cols.add(f1);
            cols.add(f2);
            sd.setCols(cols);

            sd.setLocation("hdfs://user/hive/warehouse/mx");

            sd.setInputFormat("org.apache.hadoop.mapred.TextInputFormat");
            
sd.setOutputFormat("org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat");

            SerDeInfo serdeInfo = new SerDeInfo();
            
serdeInfo.setSerializationLib("org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe");
            Map<String, String> serdeParameters = new HashMap<String, String>();
            serdeParameters.put("field.delim", ",");
            serdeInfo.setParameters(serdeParameters);
            sd.setSerdeInfo(serdeInfo);
            table.setSd(sd);

            table.setOwner("root");
            table.setTableType("MANAGED_TABLE");
            client.createTable(table);

```


stack trace:

```

org.apache.hadoop.hive.metastore.api.MetaException: 
java.lang.NullPointerException
        at 
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$create_table_with_environment_context_result$create_table_with_environment_context_resultStandardScheme.read(ThriftHiveMetastore.java:41498)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at 
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$create_table_with_environment_context_result$create_table_with_environment_context_resultStandardScheme.read(ThriftHiveMetastore.java:41466)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at 
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$create_table_with_environment_context_result.read(ThriftHiveMetastore.java:41392)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:86) 
~[org.apache.thrift.libthrift-0.9.3.jar:0.9.3]
        at 
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.recv_create_table_with_environment_context(ThriftHiveMetastore.java:1183)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at 
org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.create_table_with_environment_context(ThriftHiveMetastore.java:1169)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at 
org.apache.hadoop.hive.metastore.HiveMetaStoreClient.create_table_with_environment_context(HiveMetaStoreClient.java:2323)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at 
org.apache.hadoop.hive.metastore.HiveMetaStoreClient.createTable(HiveMetaStoreClient.java:736)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]
        at 
org.apache.hadoop.hive.metastore.HiveMetaStoreClient.createTable(HiveMetaStoreClient.java:724)
 ~[org.apache.hive.hive-metastore-2.1.0.jar:2.1.0]


```


Is this a bug? Do you have any idea?


Reply via email to