简体   繁体   English

Databricks 与 python 3 为 Azure SQl 数据库和 Z23EEEB4347BDD265DFC6B7EE9A3B7

[英]Databricks with python 3 for Azure SQl Databas and python

I am trying to use Azure Databricks in order to:我正在尝试使用 Azure Databricks 来:

1- insert rows into table of Azure SQL Databse with python 3. I cannot see a documentation about insert rows. 1-将行插入 Azure SQL 数据库与 python 的表中 3. 我看不到有关插入行的文档。 (I have use this link to connect to the database Doc and it is working). (我已使用此链接连接到数据库Doc并且它正在工作)。

2- Save Csv file in my datalake 2- 在我的数据湖中保存 Csv 文件

3- Create Table from Dataframe if possible 3- 如果可能,从 Dataframe 创建表

Thanks for your help and sorry for my novice questions感谢您的帮助,并对我的新手问题感到抱歉

**1- insert rows into table of Azure SQL Databse with python 3. ** **1- 将行插入 Azure SQL 数据库与 python 3 的表中。**

Azure Databricks has installed the JDBC driver. Azure Databricks 已安装 JDBC 驱动程序。 We can use JDBC driver to write data to SQL Server with a Dataframe.我们可以使用 JDBC 驱动程序将数据写入 SQL 服务器与 Dataframe。 For more details, please refer to here .更多详情,请参阅此处

For example例如

jdbcHostname = "<hostname>"
jdbcDatabase = ""
jdbcPort = 1433
jdbcUrl = "jdbc:sqlserver://{0}:{1};database={2}".format(jdbcHostname, jdbcPort, jdbcDatabase)
connectionProperties = {
  "user" : jdbcUsername,
  "password" : jdbcPassword,
  "driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
}

#write
df=spark.createDataFrame([(1, "test1"),(2,"test2")],["id", "name"])
df.write.jdbc(url=jdbcUrl,table="users",mode="overwrite",properties=connectionProperties)

#check

df1 = spark.read.jdbc(url=jdbcUrl, table='users', properties=connectionProperties)
display(df1)

.

2- Create Table from Dataframe 2- 从 Dataframe 创建表

If you want to create a DataBricks table from datafarme, you can use the method registerTempTable or saveAsTable .如果要从 datafarme 创建 DataBricks 表,可以使用方法registerTempTablesaveAsTable

registerTempTable creates an in-memory table that is scoped to the cluster in which it was created. registerTempTable创建一个内存表,该表的范围仅限于创建它的集群。 The data is stored using Hive's highly-optimized, in-memory columnar format.数据使用 Hive 高度优化的内存列格式存储。

saveAsTable creates a permanent, physical table stored in S3 using the Parquet format. saveAsTable使用 Parquet 格式创建存储在 S3 中的永久物理表。 This table is accessible to all clusters including the dashboard cluster.该表可供所有集群访问,包括仪表板集群。 The table metadata including the location of the file(s) is stored within the Hive metastore.包含文件位置的表元数据存储在 Hive 元存储中。

For more details, please refer to here and here .更多详情,请参阅此处此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM