ucanaccess继续重复列名作为数据
我在ucanaccess 5.0.1
in databricks 9.1lts(spark 3.1.2,scala 2.1.2)
,出于任何原因,我使用以下代码来阅读 DB表它一直将列名称作为记录本身(我尝试添加更多记录并获得相同的结果)
单个记录访问
ID Field1 Field2
2 key1 column2
3 key2 column2-1
。
connectionProperties = {
"driver" : "net.ucanaccess.jdbc.UcanaccessDriver"
}
url = "jdbc:ucanaccess:///dbfs/mnt/internal/Temporal/Database1.accdb"
df = spark.read.jdbc(url=url, table="Table1", properties=connectionProperties)
结果看起来这样:
df.printSchema()
df.count()
root
|-- Field1: string (nullable = true)
|-- Field2: string (nullable = true)
|-- ID: string (nullable = true)
Out[21]: 2
df.show()
+------+------+---+
|Field1|Field2| ID|
+------+------+---+
|Field1|Field2| ID|
|Field1|Field2| ID|
+------+------+---+
有什么想法/建议吗?
I was using UcanAccess 5.0.1
in databricks 9.1LTS (Spark 3.1.2, Scala 2.1.2)
, and for whatever reasons when I use the following code to read in a single record Access db table it keeps treating the column names as the record itself (I've tried adding more records and got the same results.)
The Access db table looks like this (2 records):
ID Field1 Field2
2 key1 column2
3 key2 column2-1
The python code looks like this:
connectionProperties = {
"driver" : "net.ucanaccess.jdbc.UcanaccessDriver"
}
url = "jdbc:ucanaccess:///dbfs/mnt/internal/Temporal/Database1.accdb"
df = spark.read.jdbc(url=url, table="Table1", properties=connectionProperties)
And the result looks like this:
df.printSchema()
df.count()
root
|-- Field1: string (nullable = true)
|-- Field2: string (nullable = true)
|-- ID: string (nullable = true)
Out[21]: 2
df.show()
+------+------+---+
|Field1|Field2| ID|
+------+------+---+
|Field1|Field2| ID|
|Field1|Field2| ID|
+------+------+---+
Any idea/suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的数据在第一行中具有列名,则可以尝试
header = true
,将第一行设置为列标题。示例代码 -
但是,如果您的数据没有列标题,则需要明确定义列名,然后将其分配为列标题。
示例代码 -
您也可以参考此答案 Alberto Bonsanto
参考 - https://learn.microsoft.com/en-comrosoft.com/en-en-us/azure/ databricks/data/data-ources/sql-databases#read-data-from-jdbc
If your data has column names in a first row, you can try
header = True
, to set first row as column headers.Sample code –
But if your data does not have column headers, you need to explicitly define column names and then assign them as column headers.
Sample code –
You can also refer this answer by Alberto Bonsanto
Reference - https://learn.microsoft.com/en-us/azure/databricks/data/data-sources/sql-databases#read-data-from-jdbc
事实证明,JDBC代码中存在一个错误([https://stackoverflow.com/questions/631777736/spark-read-ap-read-as-jdbc-redurn-redurn-rown-all-rows-as-columns-name-name])
我添加了以下内容代码,现在UCanaccess驱动程序正常工作:
然后
Display(DF)
将显示turns out that there was a bug in the jdbc code ([https://stackoverflow.com/questions/63177736/spark-read-as-jdbc-return-all-rows-as-columns-name])
I added the following code and now the ucanaccess driver works fine:
Then
display(df)
would show