How to write table to Hive
In my scenario I need to use Tispark to input tables from TiDB into Hive. But TiContext does not seem to switch to hiveContext. Here is my code
val spark: SparkSession = SparkSession.builder
.appName("TiSpark Application")
.enableHiveSupport()
.getOrCreate()
val ti: TiContext = new TiContext(spark, List("10.96.185.39:2379"))
ti.tidbMapDatabase("test")
logger.info("======== TiDB load begin =========")
val tiDF = spark.sql("select * from dump_task").toDF()
tiDF.createGlobalTempView("source_data")
logger.info("======== TiDB load end =========")
tiDF.write.mode(SaveMode.Overwrite).saveAsTable("test_tispark_2_hive");
Sorry for late responding. In shell and job mode, TiSpark didn't touch meta utilities link to hive. So writing to Hive should be ok. But we haven't tested such case. We are preparing a environment with both Hive and Spark for you case. We will reach out for you once done soon.
Please confirm this ASAP. @birdstorm
I did a brief test on CDH cluster with downloaded Spark 2.1.1 running on JDK8. I was able to connect to Hive by copying hive-site.xml to spark/conf Then I did below steps:
val df = spark.sql("select col1, col2 from test").toDF // test is a table in TiDB
df.write.mode("overwrite").saveAsTable("test_tispark_2_hive")
And then I switch to Hive CLI and I can read it back. Can you explain more about what went wrong? Any error message?
BTW, I exported HADOOP_CONF_DIR before starting spark. That allows spark to write to HDFS.
Close for now, feel free to reopen it when you see fit. @ayzmkk