-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow.py
More file actions
65 lines (59 loc) · 1.8 KB
/
show.py
File metadata and controls
65 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
from pyspark.sql import SparkSession
# spark = (
# SparkSession
# .builder
# .remote("sc://spark-connect.svc.cluster.local:15002")
# .getOrCreate()
# )
# print(type(SparkSession.getActiveSession()))
#
# spark.catalog.listDatabases()
#
# from sqlalchemy_scsql.dbapi.dbapi import connect
# # Create and configure logger
# logging.basicConfig()
# # Creating an object
# logger=logging.getLogger()
#
# # Setting the threshold of logger to DEBUG
# logger.setLevel(logging.DEBUG)
# conn = connect(config={"a":"b"})
# cursor = conn.cursor()
#
# # Выполняем SQL-запрос
# cursor.execute("show databases;")
#
# # Получаем и выводим результаты
# rows = cursor.fetchall()
# for row in rows:
# print(row)
# Закрываем курсор и соединение
# cursor.close()
# conn.close()
# from sqlalchemy_scsql.dbapi.dbapi import connect
# Create and configure logger
# Creating an object
logger=logging.getLogger()
# Setting the threshold of logger to DEBUG
logger.setLevel(logging.DEBUG)
from sqlalchemy import create_engine
from sqlalchemy.dialects import registry
registry.register("sc", "sqlalchemy_scsql", "SparkConnectDialect")
# Создание движка для подключения к PySpark Connect
engine = create_engine("sc://localhost:15002")
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
# metadata_obj = MetaData()
# users = Table(
# "users",
# metadata_obj,
# Column("id", Integer, primary_key=True),
# Column("name", String),
# Column("fullname", String),
# )
# metadata_obj.create_all(engine)
# Выполнение SQL-запроса через SQLAlchemy
with engine.connect() as connection:
result = connection.execute("SHOW DATABASES;")
for row in result:
print(row)