jdbc - How to set Hive configuration property hive.exec.dynamic.partition from Java code -
i have made java script connect hive using hiveserver2 , create table , manage tables, simple create, drop, insert data works fine.
i want create external table partition, need change value following hive property,
hive.exec.dynamic.partition = true hive.exec.dynamic.partition.mode = nonstrict
in hive cli can using set , property name, how can done in java code.
here java code:
public class hivejdbcclient { private static string strdrivername = "org.apache.hive.jdbc.hivedriver"; public static void main(string[] args) throws sqlexception { try{ class.forname(strdrivername); } catch (classnotfoundexception e){ e.printstacktrace(); system.out.println("no class found"); system.exit(1); } connection con = drivermanager.getconnection("jdbc:hive2://172.11.1.11:10000/default","root","root123"); statement stmt = con.createstatement(); string strtablename = "testtable"; //stmt.execute("drop table " + strtablename); //creating staging table load data partition data string strstagingtablesql = "create table if not exists "+strtablename+"_staging "+ " (sequence_no decimal, date_key int, activity_time_key int, ds_key int, ds_value decimal, tl_date_key int) row format delimited fields terimanted '~'"; string strmaintablesql = "create external table if not exists "+strtablename+" (sequence_no decimal, activity_time_key int, ds_key int, ds_value decimal, tl_date_key int) partitioned (date_key int) row format delimited fields terminated '~' location '/informatica/dwh/teradata/testtable'"; string strcreatesql = "create external table if not exists "+ strtablename + " (key int, value string) row format delimited fields terminated ','"; boolean res = stmt.execute(strcreatesql); //show tables string sql = "show tables '" + strtablename + "'"; resultset res1 = stmt.executequery(sql); if (res1.next()){ system.out.println(res1.getstring(1)); } sql = "describe "+ strtablename; system.out.println("running: "+ sql); res1 = stmt.executequery(sql); while (res1.next()){ system.out.println(res1.getstring(1) + "\t" + res1.getstring(2)); } // load data table // note: filepath has local hive server // note: /tmp/a.txt ctrl-a separated file 2 fields per line string strfilepath = "/informatica/testing_hive_client_java.txt"; sql = "load data inpath '" + strfilepath + "' table " + strtablename; system.out.println("running: " + sql); res = stmt.execute(sql); sql = "select count(1) "+ strtablename; system.out.println("running: "+ sql); res1 = stmt.executequery(sql); while(res1.next()){ system.out.println(res1.getstring(1)); } }// end of main }// end of class
experts please pour in thoughts.
i able solve problem following code.
boolean reshivepropertytest = stmt .execute("set hive.exec.dynamic.partition = true"); reshivepropertytest = stmt .execute("set hive.exec.dynamic.partition.mode = nonstrict");
as code jdbc client code , execute go , execute in hive , worked me.
Comments
Post a Comment