Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's SparkSQL SQL query to write into JDBC table?

For SQL query in Spark.

For read, we can read jdbc by

CREATE TEMPORARY TABLE jdbcTable
USING org.apache.spark.sql.jdbc
OPTIONS dbtable ...;

For write, what is the query to write the data to the remote JDBC table using SQL?

NOTE: I want it to be SQL query. plz provide the pure "SQL query" that can write to jdbc when using HiveContext.sql(...) of SparkSQL.

like image 885
WeiChing 林煒清 Avatar asked Nov 27 '22 14:11

WeiChing 林煒清


1 Answers

An INSERT OVERWRITE TABLE will write to your database using the JDBC connection:

DROP TABLE IF EXISTS jdbcTemp;
CREATE TABLE jdbcTemp
USING org.apache.spark.sql.jdbc
OPTIONS (...);

INSERT OVERWRITE TABLE jdbcTemp
SELECT * FROM my_spark_data;
DROP TABLE jdbcTemp;
like image 195
Tristan Reid Avatar answered Dec 04 '22 10:12

Tristan Reid