Erstellen Funke Dataframe aus einer SQL-Abfrage

Ich bin sicher, dies ist eine einfache SQLContext Frage, aber ich finde keine Antwort in der Funke docs oder Stackoverflow

Möchte ich, um einen Funken zu erzeugen Dataframe von einer SQL-Abfrage auf der MySQL -

Ich habe zum Beispiel eine komplizierte MySQL-Abfrage wie

SELECT a.X,b.Y,c.Z FROM FOO as a JOIN BAR as b ON ... JOIN ZOT as c ON ... WHERE ...

und ich will einen Dataframe mit den Spalten X,Y und Z

Ich herausgefunden, wie das laden ganzer Tabellen in Funken, und ich konnte laden Sie alle, und führen Sie dann die Verbindung und-Auswahl. Das ist jedoch sehr ineffizient. Ich möchte nur zum laden der Tabelle generiert, die durch meine SQL-Abfrage.

Hier ist meine derzeitige Annäherung der code, das nicht funktioniert. Mysql-connector hat eine option "dbtable", die verwendet werden können, laden Sie eine ganze Tabelle. Ich hoffe, es ist ein Weg, um eine Abfrage

  val df = sqlContext.format("jdbc").
    option("url", "jdbc:mysql://localhost:3306/local_content").
    option("driver", "com.mysql.jdbc.Driver").
    option("useUnicode", "true").
    option("continueBatchOnError","true").
    option("useSSL", "false").
    option("user", "root").
    option("password", "").
    sql(
"""
select dl.DialogLineID, dlwim.Sequence, wi.WordRootID from Dialog as d
join DialogLine as dl on dl.DialogID=d.DialogID
join DialogLineWordInstanceMatch as dlwim o n dlwim.DialogLineID=dl.DialogLineID
join WordInstance as wi on wi.WordInstanceID=dlwim.WordInstanceID
join WordRoot as wr on wr.WordRootID=wi.WordRootID
where d.InSite=1 and dl.Active=1
limit 100
"""
    ).load()

Dank
Peter

InformationsquelleAutor user1902291 | 2016-07-14

Schreibe einen Kommentar