尝试在Databricks Apache表中查找变量失败- 为什么?

huangapple go评论66阅读模式
英文:

Trying to Find Variable in Databricks Apache Table Fails- Why?

问题

org.apache.spark.SparkException: 无法获取默认数据库的表格

... 尝试运行以下代码时出现此错误:

  databaseName = "database"
  desiredColumn = "work_unit_code"
  database = spark.sql(f"show tables in {databaseName} ").collect()
  display(database)

  tablenames = []
  for row in database:
         cols = spark.table(row.tableName).columns
         **listColumns= spark.table(row.tableName).columns**
         if desiredColumn in listColumns:
              tablenames.append(row.tableName)

有人知道发生了什么吗? 请提前感谢。

尝试在特定数据库表格中汇总总列,然后迭代列,看看是否存在特定变量。

英文:

I am running Apache Spark 3.3.0, Scala 2.12, and get this error:

org.apache.spark.SparkException: Unable to fetch tables of db default

... when trying to run this code:

  databaseName = "database"
  desiredColumn = "work_unit_code"
  database = spark.sql(f"show tables in {databaseName} ").collect()
  display(database)

  tablenames = []
  for row in database:
         cols = spark.table(row.tableName).columns
         **listColumns= spark.table(row.tableName).columns**
         if desiredColumn in listColumns:
              tablenames.append(row.tableName)

Does anyone know what's going on, please? Thanks in advance.

Trying to aggregate total columns within a specific database table, then iterate through columns to see if a specific variable exists there.

答案1

得分: 1

因为tableName列只包含表名,而不包括数据库名,所以会发生这种情况。

spark.table(row.tableName)修改为spark.table(f"{databaseName}.{row.tableName}")

英文:

This happens because the tableName column contains just the table name, but not the database name.

Change spark.table(row.tableName) to the spark.table(f"{databaseName}.{row.tableName})

huangapple
  • 本文由 发表于 2023年7月13日 00:48:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76672847.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定