Guest User

Untitled

a guest
Jan 6th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.81 KB | None | 0 0
  1. Prerequisites :
  2. >>Enable hive interactive server in hive
  3.  
  4. >>Get following details from hive for spark
  5.  
  6. spark.hadoop.hive.llap.daemon.service.hosts @llap0
  7. spark.sql.hive.hiveserver2.jdbc.url jdbc:hive2://c420-node2.squadron-labs.com:2181,c420-node3.squadron-labs.com:2181,c420-node4.squadron-labs.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-interactive
  8. spark.datasource.hive.warehouse.load.staging.dir /tmp
  9. spark.datasource.hive.warehouse.metastoreUri thrift://c420-node3.squadron-labs.com:9083
  10. spark.security.credentials.hiveserver2.enabled false
  11.  
  12.  
  13.  
  14. Basic testing :
  15.  
  16. 1) Create a table employee in hive and load some data
  17. eg:
  18. Create table
  19. ----------------
  20.  
  21. ```CREATE TABLE IF NOT EXISTS employee ( eid int, name String, salary String, destination String)
  22. COMMENT 'Employee details'
  23. ROW FORMAT DELIMITED
  24. FIELDS TERMINATED BY ','
  25. LINES TERMINATED BY '\n'
  26. STORED AS TEXTFILE;
  27. ```
  28. Load data data.txt file into hdfs
  29. ---------------
  30. ```
  31. 1201,Gopal,45000,Technical manager
  32. 1202,Manisha,45000,Proof reader
  33. 1203,Masthanvali,40000,Technical writer
  34. 1204,Kiran,40000,Hr Admin
  35. 1205,Kranthi,30000,Op Admin
  36. ```
  37.  
  38. ```LOAD DATA INPATH '/tmp/data.txt' OVERWRITE INTO TABLE employee;```
  39.  
  40. 2) kinit to the spark user and run
  41.  
  42. spark-shell --master yarn --conf "spark.security.credentials.hiveserver2.enabled=false" --conf "spark.sql.hive.hiveserver2.jdbc.url=jdbc:hive2://c420-node2.squadron-labs.com:2181,c420-node3.squadron-labs.com:2181,c420-node4.squadron-labs.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-interactive;principal=hive/_HOST@HWX.COM" --conf "spark.datasource.hive.warehouse.metastoreUri=thrift://c420-node3.squadron-labs.com:9083" --conf "spark.datasource.hive.warehouse.load.staging.dir=/tmp/" --conf "spark.hadoop.hive.llap.daemon.service.hosts=@llap0" --conf "spark.hadoop.hive.zookeeper.quorum=c420-node2.squadron-labs.com:2181,c420-node3.squadron-labs.com:2181,c420-node4.squadron-labs.com:2181" --jars /usr/hdp/current/hive_warehouse_connector/hive-warehouse-connector-assembly-1.0.0.3.0.1.0-187.jar
  43.  
  44. Note: spark.security.credentials.hiveserver2.enabled should be set to false for YARN client deploy mode, and true for YARN cluster deploy mode (by default). This configuration is required for a Kerberized cluster
  45.  
  46. 3) run following code in scala shell to view the table data
  47. import com.hortonworks.hwc.HiveWarehouseSession
  48. val hive = HiveWarehouseSession.session(spark).build()
  49. hive.execute("show tables").show
  50. hive.executeQuery("select * from employee").show
  51.  
  52.  
  53.  
  54. 4) To apply common properties by default, add following setting into ambari spark2 custom conf
  55.  
  56.  
  57. spark.sql.hive.hiveserver2.jdbc.url=jdbc:hive2://c420-node2.squadron-labs.com:2181,c420-node3.squadron-labs.com:2181,c420-node4.squadron-labs.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-interactive;principal=hive/_HOST@HWX.COM
  58. spark.datasource.hive.warehouse.metastoreUri=thrift://c420-node3.squadron-labs.com:9083
  59. spark.datasource.hive.warehouse.load.staging.dir=/tmp/
  60. spark.hadoop.hive.llap.daemon.service.hosts=@llap0
  61. spark.hadoop.hive.zookeeper.quorum=c420-node2.squadron-labs.com:2181,c420-node3.squadron-labs.com:2181,c420-node4.squadron-labs.com:2181
  62.  
  63.  
  64. 5) spark-shell --master yarn --conf "spark.security.credentials.hiveserver2.enabled=false" --jars /usr/hdp/current/hive_warehouse_connector/hive-warehouse-connector-assembly-1.0.0.3.0.1.0-187.jar
  65. Note: Common properties are read from spark default properties
  66.  
  67. 6) run following code in scala shell to view the hive table data
  68. ```
  69. import com.hortonworks.hwc.HiveWarehouseSession
  70. val hive = HiveWarehouseSession.session(spark).build()
  71. hive.execute("show tables").show
  72. hive.executeQuery("select * from employee").show
  73. ```
  74.  
  75. 7) To integrate HWC in Livy2
  76.  
  77. a) add following property in Custom livy2-conf
  78. livy.file.local-dir-whitelist=/usr/hdp/current/hive_warehouse_connector/
  79. b) Add hive-site.xml to /usr/hdp/current/spark2-client/conf on all cluster nodes.
  80.  
  81. c) In livy2 interpreter settings add following
  82.  
  83. livy.spark.hadoop.hive.llap.daemon.service.hosts @llap0
  84. livy.spark.security.credentials.hiveserver2.enabled true
  85. livy.spark.sql.hive.hiveserver2.jdbc.url jdbc:hive2://c420-node2.squadron-labs.com:2181,c420-node3.squadron-labs.com:2181,c420-node4.squadron-labs.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2-interactive
  86. livy.spark.sql.hive.hiveserver2.jdbc.url.principal hive/_HOST@HWX.COM
  87. livy.spark.yarn.security.credentials.hiveserver2.enabled true
  88. livy.spark.jars file:///usr/hdp/current/hive_warehouse_connector/hive-warehouse-connector-assembly-1.0.0.3.0.1.0-187.jar
  89.  
  90. d) Restart livy2 interpreter
  91.  
  92. e) in first paragraph add
  93. %livy2
  94. import com.hortonworks.hwc.HiveWarehouseSession
  95. val hive = HiveWarehouseSession.session(spark).build()
  96.  
  97. f) in second paragraph add
  98. %livy2
  99. hive.executeQuery("select * from employee").show
Add Comment
Please, Sign In to add comment