tispark icon indicating copy to clipboard operation
tispark copied to clipboard

How to write table to Hive

Open ayzmkk opened this issue 8 years ago • 5 comments

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");

ayzmkk avatar Jan 09 '18 02:01 ayzmkk

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.

ilovesoup avatar Jan 17 '18 07:01 ilovesoup

Please confirm this ASAP. @birdstorm

ilovesoup avatar Jan 23 '18 18:01 ilovesoup

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?

ilovesoup avatar Jan 28 '18 21:01 ilovesoup

BTW, I exported HADOOP_CONF_DIR before starting spark. That allows spark to write to HDFS.

ilovesoup avatar Jan 28 '18 22:01 ilovesoup

Close for now, feel free to reopen it when you see fit. @ayzmkk

ilovesoup avatar Mar 19 '18 05:03 ilovesoup