0
1

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)にてPython(PySpark)・SQL・Scalaにより利用するSparkデータベースを変更する方法

Last updated at Posted at 2021-07-20

概要

Databricks(Spark)にて、Python(PySpark)・SQL・Scalaのそれぞれの言語別に利用するSparkデータベースを変更する方法を共有します。

手順

事前準備

# 現在のデータベースを`default`へ初期化
setCurrentDatabase = spark.catalog.setCurrentDatabase('default')
currentDatabase = spark.catalog.currentDatabase()
print(currentDatabase)
%sql
--切り替え対象のデータベースを作成
create database if not exists qiita;

image.png

Python(Pyspark)で実施する方法

%python

database = 'qiita'
setCurrentDatabase = spark.catalog.setCurrentDatabase(database)


currentDatabase = spark.catalog.currentDatabase()
print(currentDatabase)

image.png

SQLで実施する方法

%sql

use qiita;

select current_database() 

image.png

Scalaで実施する方法

%scala
val database = "qiita"
val setCurrentDatabase = spark.catalog.setCurrentDatabase(database)


val currentDatabase = spark.catalog.currentDatabase
println(currentDatabase)

image.png

関連記事

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?