0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Databricks(Spark)にてScalaの関数で取得可能なDDL文字列をPythonで取得する方法

Posted at

概要

Databricks(Spark)にてScalaの関数で取得可能なDDL文字列をPythonで取得する方法を共有します。
DDL文字列を取得するにはScalaの関数を利用する必要があり、Py4J経由で利用可能でした。

詳細は下記のGithub pagesのページをご確認ください。

コードを実行したい方は、下記のdbcファイルを取り込んでください。

検証環境

databricks runtime: 8.1.x-scala2.12
Python version: 3.8.8
pyspark version: 3.1.1.dev0

実施手順

PythonからScalaの関数をPy4j経由で利用する方法

json_data = df.schema.json()
 
schema = spark.sparkContext._jvm.org.apache.spark.sql.types.DataType.fromJson(json_data).toDDL()
 
schema

image.png

関連記事

ノートブックをGithub Pageによる共有方法

Databricks(Azure Databricks)でGithub経由でノートブックを共有する方法 - Qiita

Githubのファイルをインポートする手順

DatabricksにてGithub上にあるdbcファイルのインポート方法について - Qiita

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?