You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by pgb <pb...@doximity.com> on 2016/08/02 20:25:22 UTC
In 2.0.0, is it possible to fetch a query from an external database
(rather than grab the whole table)?
I'm interested in learning if it's possible to grab the results set from a
query run on an external database as opposed to grabbing the full table and
manipulating it later. The base code I'm working with is below (using Spark
2.0.0):
```
from pyspark.sql import SparkSession
df = spark.read\
.format("jdbc")\
.option("url", "jdbc:mysql://localhost:port")\
.option("dbtable", "schema.tablename")\
.option("user", "username")\
.option("password", "password")\
.load()
```
Many thanks,
Pat
--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/In-2-0-0-is-it-possible-to-fetch-a-query-from-an-external-database-rather-than-grab-the-whole-table-tp27453.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org
Re: In 2.0.0, is it possible to fetch a query from an external
database (rather than grab the whole table)?
Posted by Mich Talebzadeh <mi...@gmail.com>.
You don't need to get full table. This is getting data from an Oracle table
val c = HiveContext.load("jdbc",
Map("url" -> _ORACLEserver,0
"dbtable" -> "(SELECT to_char(CHANNEL_ID) AS CHANNEL_ID, CHANNEL_DESC FROM
sh.channels WHERE CHANNEL_ID <= 1000)",
"user" -> _username,
"password" -> _password))
Obviously your SQL clause can limit the result set returned.
Otherwise you can run the code within RDBMS itself into a staging table and
then use Spark to access the table through JDBC.
You cannot run the code from Spark against data in RDBMS. You have to fetch
that data into a DF and say into a temp table
c.registerTempTable("t_c")
then that table t_c can be used in Spark SQL if you wish
HTH
Dr Mich Talebzadeh
LinkedIn * https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw
<https://www.linkedin.com/profile/view?id=AAEAAAAWh2gBxianrbJd6zP6AcPCCdOABUrV8Pw>*
http://talebzadehmich.wordpress.com
*Disclaimer:* Use it at your own risk. Any and all responsibility for any
loss, damage or destruction of data or any other property which may arise
from relying on this email's technical content is explicitly disclaimed.
The author will in no case be liable for any monetary damages arising from
such loss, damage or destruction.
On 2 August 2016 at 23:38, Jacek Laskowski <ja...@japila.pl> wrote:
> Hi,
>
> Don't think so.
>
> Pozdrawiam,
> Jacek Laskowski
> ----
> https://medium.com/@jaceklaskowski/
> Mastering Apache Spark 2.0 http://bit.ly/mastering-apache-spark
> Follow me at https://twitter.com/jaceklaskowski
>
>
> On Tue, Aug 2, 2016 at 10:25 PM, pgb <pb...@doximity.com> wrote:
> > I'm interested in learning if it's possible to grab the results set from
> a
> > query run on an external database as opposed to grabbing the full table
> and
> > manipulating it later. The base code I'm working with is below (using
> Spark
> > 2.0.0):
> >
> > ```
> > from pyspark.sql import SparkSession
> >
> > df = spark.read\
> > .format("jdbc")\
> > .option("url", "jdbc:mysql://localhost:port")\
> > .option("dbtable", "schema.tablename")\
> > .option("user", "username")\
> > .option("password", "password")\
> > .load()
> > ```
> >
> > Many thanks,
> > Pat
> >
> >
> >
> > --
> > View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/In-2-0-0-is-it-possible-to-fetch-a-query-from-an-external-database-rather-than-grab-the-whole-table-tp27453.html
> > Sent from the Apache Spark User List mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe e-mail: user-unsubscribe@spark.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscribe@spark.apache.org
>
>
Re: In 2.0.0, is it possible to fetch a query from an external
database (rather than grab the whole table)?
Posted by Jacek Laskowski <ja...@japila.pl>.
Hi,
Don't think so.
Pozdrawiam,
Jacek Laskowski
----
https://medium.com/@jaceklaskowski/
Mastering Apache Spark 2.0 http://bit.ly/mastering-apache-spark
Follow me at https://twitter.com/jaceklaskowski
On Tue, Aug 2, 2016 at 10:25 PM, pgb <pb...@doximity.com> wrote:
> I'm interested in learning if it's possible to grab the results set from a
> query run on an external database as opposed to grabbing the full table and
> manipulating it later. The base code I'm working with is below (using Spark
> 2.0.0):
>
> ```
> from pyspark.sql import SparkSession
>
> df = spark.read\
> .format("jdbc")\
> .option("url", "jdbc:mysql://localhost:port")\
> .option("dbtable", "schema.tablename")\
> .option("user", "username")\
> .option("password", "password")\
> .load()
> ```
>
> Many thanks,
> Pat
>
>
>
> --
> View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/In-2-0-0-is-it-possible-to-fetch-a-query-from-an-external-database-rather-than-grab-the-whole-table-tp27453.html
> Sent from the Apache Spark User List mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe e-mail: user-unsubscribe@spark.apache.org
>
---------------------------------------------------------------------
To unsubscribe e-mail: user-unsubscribe@spark.apache.org