Hướng dẫn how do you use a python variable in sql query in databricks? - làm thế nào để bạn sử dụng một biến python trong truy vấn sql trong cơ sở dữ liệu?

6

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi muốn sử dụng một câu lệnh WHERE với hai biến trong mệnh đề WHERE. Tôi đã thực hiện nghiên cứu về việc xem xét cách sử dụng các biến trong các câu lệnh SQL trong dữ liệu và chèn các biến bằng Python, không hoạt động. Tôi đã cố gắng thực hiện các giải pháp được cung cấp nhưng nó không hoạt động.

a= 17091990
b = 30091990

df = spark.sql[' SELECT * FROM table WHERE date between "a" AND "b" ']

  • Databricks

Hỏi ngày 20 tháng 8 năm 2019 lúc 1:09Aug 20, 2019 at 1:09

JozamvgjozamvgJozamvg

1472 Huy hiệu bạc10 Huy hiệu đồng2 silver badges10 bronze badges

6

  • Lỗi bạn đang gặp phải là gì? Có lẽ vì định dạng ngày? Định dạng ngày phải được phân tách bằng dấu gạch ngang [-], một số thứ như thế này tôi nghĩ a = '09 -17-1990 'và b = '09 -30-1990'

    Ngày 20 tháng 8 năm 2019 lúc 1:17

  • Bạn có thể làm rõ cách nó "không hoạt động". Bạn có thể cung cấp một số dữ liệu mẫu và cũng cho thấy đầu ra thực tế dự kiến ​​là gì không?

    Ngày 20 tháng 8 năm 2019 lúc 1:17

  • Bạn có thể làm rõ cách nó "không hoạt động". Bạn có thể cung cấp một số dữ liệu mẫu và cũng cho thấy đầu ra thực tế dự kiến ​​là gì không?

    @Ronelcalinisan không, giá trị của nó là một int

  • Ngày 20 tháng 8 năm 2019 lúc 1:39

    @Dijkgraaf Tôi không biết làm thế nào để làm điều đó. Tôi đã thử một cách khác để sử dụng các biến trong truy vấn nhưng không hoạt động

  • Ngày 20 tháng 8 năm 2019 lúc 1:40

    @Jozamvg vậy ngày của bạn có int và không ngày?

Ngày 20 tháng 8 năm 2019 lúc 1:42

1 câu trả lờiAug 20, 2019 at 7:55

Sau đó, bạn có thể truy vấn nó ..

Làm thế nào để bạn khai báo một biến trong Databricks?

Đây là một chút của nồi hơi, nhưng nó hoạt động như thế này:.

Hằng số tích hợp [cho
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
24] trên trang web Python

  • Nhận xét
  • Gửi và xem phản hồi cho
  • Chúng ta có thể sử dụng biến Python trong truy vấn SQL không?

Chúng ta thường cần chuyển các biến cho SQL Chọn truy vấn trong mệnh đề WHERE để kiểm tra một số điều kiện. Trong biểu mẫu đăng ký người dùng, người dùng nhập chi tiết của anh ấy/cô ấy. Bạn có thể lấy các giá trị đó trong các biến Python và chèn chúng vào một bảng.

Làm thế nào để bạn chuyển một biến python cho truy vấn SQL trong pyspark?

Bạn có thể chuyển các tham số/đối số cho các câu lệnh SQL của mình bằng cách tạo chuỗi SQL bằng cách sử dụng scala/python và chuyển nó sang sqlcontext ..

  • Tham số của bạn. val p1 = "['0001', '0002', '0003']" ....
  • Xây dựng truy vấn. ....

Sau đó, bạn có thể truy vấn nó ..

  • Làm thế nào để bạn khai báo một biến trong Databricks?

    Đây là một chút của nồi hơi, nhưng nó hoạt động như thế này:.

    • Nhập mô -đun TensorFlow và gọi nó là TF ..Server Hostname value in the Advanced Options > JDBC/ODBC tab for your cluster.
    • Tạo một giá trị không đổi gọi là X và cho nó giá trị số 35 ..HTTP Path value in the Advanced Options > JDBC/ODBC tab for your cluster.
    • Tạo một biến gọi là y và định nghĩa nó là phương trình x + 5 ..

    Ghi chú

    Là một thông lệ bảo mật tốt nhất, bạn không nên mã hóa thông tin này vào mã của mình. Thay vào đó, bạn nên lấy thông tin này từ một vị trí an toàn. Ví dụ: các ví dụ mã sau trong bài viết này sử dụng các biến môi trường.

    Sql warehouse

    • Tên máy chủ máy chủ của kho SQL. Bạn có thể nhận được điều này từ giá trị tên máy chủ máy chủ trong tab Chi tiết kết nối cho kho SQL của bạn.Server Hostname value in the Connection Details tab for your SQL warehouse.
    • Đường dẫn HTTP của kho SQL. Bạn có thể nhận được điều này từ giá trị đường dẫn HTTP trong tab Chi tiết kết nối cho kho SQL của bạn.HTTP Path value in the Connection Details tab for your SQL warehouse.
    • Một mã thông báo truy cập hợp lệ. Bạn có thể sử dụng mã thông báo truy cập cá nhân của Azure Databricks cho không gian làm việc. Bạn cũng có thể sử dụng mã thông báo truy cập Active Active Directory.

    Ghi chú

    Là một thông lệ bảo mật tốt nhất, bạn không nên mã hóa thông tin này vào mã của mình. Thay vào đó, bạn nên lấy thông tin này từ một vị trí an toàn. Ví dụ: các ví dụ mã sau trong bài viết này sử dụng các biến môi trường.

  • Tên máy chủ máy chủ của kho SQL. Bạn có thể nhận được điều này từ giá trị tên máy chủ máy chủ trong tab Chi tiết kết nối cho kho SQL của bạn.

Đường dẫn HTTP của kho SQL. Bạn có thể nhận được điều này từ giá trị đường dẫn HTTP trong tab Chi tiết kết nối cho kho SQL của bạn.

Một mã thông báo truy cập hợp lệ. Bạn có thể sử dụng mã thông báo truy cập cá nhân của Azure Databricks cho không gian làm việc. Bạn cũng có thể sử dụng mã thông báo truy cập Active Active Directory.

Cài đặt Trình kết nối SQL Databricks cho Thư viện Python trên máy phát triển của bạn bằng cách chạy pip install databricks-sql-connector.

  • Ví dụServer Hostname value from the requirements.
  • Các ví dụ mã sau đây trình bày cách sử dụng đầu nối Databricks SQL cho Python để truy vấn và chèn dữ liệu, siêu dữ liệu truy vấn, quản lý con trỏ và kết nối và định cấu hình ghi nhật ký.HTTP Path value from the requirements.
  • Ví dụ mã này truy xuất các giá trị biến kết nối server_hostname, http_pathaccess_token của họ từ các biến môi trường này:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
0, đại diện cho giá trị tên máy chủ máy chủ từ các yêu cầu.

  • from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    1, đại diện cho giá trị đường dẫn HTTP từ các yêu cầu.
  • from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    2, đại diện cho mã thông báo truy cập của bạn từ các yêu cầu.
  • Bạn có thể sử dụng các phương pháp khác để truy xuất các giá trị biến kết nối này. Sử dụng các biến môi trường chỉ là một cách tiếp cận giữa nhiều người.
  • Dữ liệu truy vấn
  • Chèn dữ liệu

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
1, đại diện cho giá trị đường dẫn HTTP từ các yêu cầu.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
2, đại diện cho mã thông báo truy cập của bạn từ các yêu cầu.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
2, đại diện cho mã thông báo truy cập của bạn từ các yêu cầu.

Bạn có thể sử dụng các phương pháp khác để truy xuất các giá trị biến kết nối này. Sử dụng các biến môi trường chỉ là một cách tiếp cận giữa nhiều người.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]

Dữ liệu truy vấn

Bạn có thể sử dụng các phương pháp khác để truy xuất các giá trị biến kết nối này. Sử dụng các biến môi trường chỉ là một cách tiếp cận giữa nhiều người.

Dữ liệu truy vấn

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]

Dữ liệu truy vấn

Chèn dữ liệu

Siêu dữ liệu truy vấn

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]

Chèn dữ liệu

Siêu dữ liệu truy vấn

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]

Quản lý con trỏ và kết nối

  • Định cấu hình ghi nhật ký
  • Ví dụ mã sau đây trình bày cách gọi đầu nối SQL Databricks cho Python để chạy lệnh SQL cơ bản trên kho hoặc kho SQL. Lệnh này trả về hai hàng đầu tiên từ bảng
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    3.
    • Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:
      • Đối với một lượng lớn dữ liệu, trước tiên bạn nên tải dữ liệu lên lưu trữ đám mây và sau đó thực hiện lệnh sao chép vào lệnh.
  • Có các phương pháp chuyên dụng để lấy siêu dữ liệu. Ví dụ sau lấy siêu dữ liệu về các cột trong bảng mẫu:
    • Đó là thực hành tốt nhất để đóng bất kỳ kết nối và con trỏ nào đã được hoàn thành. Điều này giải phóng các tài nguyên trên các cụm dữ liệu Azure và kho dữ liệu SQL.
      • Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:
        • Đối với một lượng lớn dữ liệu, trước tiên bạn nên tải dữ liệu lên lưu trữ đám mây và sau đó thực hiện lệnh sao chép vào lệnh.
        • Có các phương pháp chuyên dụng để lấy siêu dữ liệu. Ví dụ sau lấy siêu dữ liệu về các cột trong bảng mẫu:
    • Đó là thực hành tốt nhất để đóng bất kỳ kết nối và con trỏ nào đã được hoàn thành. Điều này giải phóng các tài nguyên trên các cụm dữ liệu Azure và kho dữ liệu SQL.
      • Bạn có thể sử dụng Trình quản lý ngữ cảnh [cú pháp
        from databricks import sql
        import os
        
        with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
        
          with connection.cursor[] as cursor:
            cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
            result = cursor.fetchall[]
        
            for row in result:
              print[row]
        
        4 được sử dụng trong các ví dụ trước] để quản lý tài nguyên hoặc gọi rõ ràng
        from databricks import sql
        import os
        
        with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
        
          with connection.cursor[] as cursor:
            cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
            result = cursor.fetchall[]
        
            for row in result:
              print[row]
        
        5:
        • Trình kết nối SQL Databricks sử dụng mô -đun ghi nhật ký tiêu chuẩn Python. Bạn có thể định cấu hình mức ghi nhật ký tương tự như sau:
        • Tham khảo API
      • Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:
        • Đối với một lượng lớn dữ liệu, trước tiên bạn nên tải dữ liệu lên lưu trữ đám mây và sau đó thực hiện lệnh sao chép vào lệnh.
        • Đối với một lượng lớn dữ liệu, trước tiên bạn nên tải dữ liệu lên lưu trữ đám mây và sau đó thực hiện lệnh sao chép vào lệnh.
        • Có các phương pháp chuyên dụng để lấy siêu dữ liệu. Ví dụ sau lấy siêu dữ liệu về các cột trong bảng mẫu:
        • Đó là thực hành tốt nhất để đóng bất kỳ kết nối và con trỏ nào đã được hoàn thành. Điều này giải phóng các tài nguyên trên các cụm dữ liệu Azure và kho dữ liệu SQL.
        • Bạn có thể sử dụng Trình quản lý ngữ cảnh [cú pháp
          from databricks import sql
          import os
          
          with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                           http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                           access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
          
            with connection.cursor[] as cursor:
              cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
              result = cursor.fetchall[]
          
              for row in result:
                print[row]
          
          4 được sử dụng trong các ví dụ trước] để quản lý tài nguyên hoặc gọi rõ ràng
          from databricks import sql
          import os
          
          with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                           http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                           access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
          
            with connection.cursor[] as cursor:
              cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
              result = cursor.fetchall[]
          
              for row in result:
                print[row]
          
          5:
        • Trình kết nối SQL Databricks sử dụng mô -đun ghi nhật ký tiêu chuẩn Python. Bạn có thể định cấu hình mức ghi nhật ký tương tự như sau:
        • Tham khảo API
        • Bưu kiện
        • Mô -đun
        • Phương pháp
        • Phương pháp
          from databricks import sql
          import os
          
          with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                           http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                           access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
          
            with connection.cursor[] as cursor:
              cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
              result = cursor.fetchall[]
          
              for row in result:
                print[row]
          
          6
        • Các lớp học
        • Lớp
          from databricks import sql
          import os
          
          with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                           http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                           access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
          
            with connection.cursor[] as cursor:
              cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
              result = cursor.fetchall[]
          
              for row in result:
                print[row]
          
          7
    • Phương pháp
      from databricks import sql
      import os
      
      with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                       http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                       access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
      
        with connection.cursor[] as cursor:
          cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
          result = cursor.fetchall[]
      
          for row in result:
            print[row]
      
      5
      • Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:
        • Đối với một lượng lớn dữ liệu, trước tiên bạn nên tải dữ liệu lên lưu trữ đám mây và sau đó thực hiện lệnh sao chép vào lệnh.
  • Có các phương pháp chuyên dụng để lấy siêu dữ liệu. Ví dụ sau lấy siêu dữ liệu về các cột trong bảng mẫu:

Định cấu hình ghi nhật ký

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
8

Ví dụ mã sau đây trình bày cách gọi đầu nối SQL Databricks cho Python để chạy lệnh SQL cơ bản trên kho hoặc kho SQL. Lệnh này trả về hai hàng đầu tiên từ bảng

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
3.

Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:

Ví dụ mã sau đây trình bày cách gọi đầu nối SQL Databricks cho Python để chạy lệnh SQL cơ bản trên kho hoặc kho SQL. Lệnh này trả về hai hàng đầu tiên từ bảng
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
3.

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
0

Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:

Ví dụ sau đây chứng minh cách chèn một lượng nhỏ dữ liệu [hàng ngàn hàng]:

Đối với một lượng lớn dữ liệu, trước tiên bạn nên tải dữ liệu lên lưu trữ đám mây và sau đó thực hiện lệnh sao chép vào lệnh.

Có các phương pháp chuyên dụng để lấy siêu dữ liệu. Ví dụ sau lấy siêu dữ liệu về các cột trong bảng mẫu:

Đó là thực hành tốt nhất để đóng bất kỳ kết nối và con trỏ nào đã được hoàn thành. Điều này giải phóng các tài nguyên trên các cụm dữ liệu Azure và kho dữ liệu SQL.

Bạn có thể sử dụng Trình quản lý ngữ cảnh [cú pháp
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
4 được sử dụng trong các ví dụ trước] để quản lý tài nguyên hoặc gọi rõ ràng
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
5:
server_hostname

Trình kết nối SQL Databricks sử dụng mô -đun ghi nhật ký tiêu chuẩn Python. Bạn có thể định cấu hình mức ghi nhật ký tương tự như sau:

Tham khảo API

Bưu kiện

Mô -đun

http_path

Trình kết nối SQL Databricks sử dụng mô -đun ghi nhật ký tiêu chuẩn Python. Bạn có thể định cấu hình mức ghi nhật ký tương tự như sau:

Tham khảo API

Bưu kiện

Mô -đun

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
6 for a cluster.
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
7 for a SQL warehouse.

access_token

Trình kết nối SQL Databricks sử dụng mô -đun ghi nhật ký tiêu chuẩn Python. Bạn có thể định cấu hình mức ghi nhật ký tương tự như sau:

Tham khảo API

Bưu kiện

Mô -đun

session_configuration

Phương pháp

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
6

Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Tham số này là tùy chọn.

Ví dụ:

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
4

http_headers

Loại:

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
5

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Tham số này là tùy chọn.

Ví dụ:

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
4

Loại:
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
5

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Kể từ phiên bản 2.0

Tham số này là tùy chọn.

Ví dụ:

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
4

Loại:
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
5

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Kể từ phiên bản 2.0

Tham số này là tùy chọn.

Ví dụ:

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
4

Loại:
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
5

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Kể từ phiên bản 2.0

mục lụcLoại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Danh mục ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, danh mục mặc định, thường là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
9, sẽ được sử dụng].

lược đồ

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học

Lớp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

lược đồ

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học

Lớp
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7Đại diện cho một kết nối với một cơ sở dữ liệu.

Phương pháp

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
5

Đóng kết nối với cơ sở dữ liệu và phát hành tất cả các tài nguyên được liên kết trên máy chủ. Bất kỳ cuộc gọi bổ sung nào đến kết nối này sẽ ném pip install databricks-sql-connector5.

Không có tham số.

  • Không có giá trị trả về.
  • Phương pháp
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    9

Trả về một cơ chế cho phép truyền tải các bản ghi trong cơ sở dữ liệu.

Trả về một đối tượng con trỏ.

mục lụcLoại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Danh mục ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, danh mục mặc định, thường là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
9, sẽ được sử dụng].

lược đồ

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Danh mục ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, danh mục mặc định, thường là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
9, sẽ được sử dụng].

lược đồ

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học

Lớp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học
Lớp
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Kể từ phiên bản 2.0

mục lục

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

http_path7http_path8http_path9
http_path8
http_path9

Danh mục ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, danh mục mặc định, thường là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
9, sẽ được sử dụng].

http_path7access_token2access_token3http_path9
access_token2
access_token3
http_path9

lược đồ

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học

Lớp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

Đại diện cho một kết nối với một cơ sở dữ liệu.

Phương pháp

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học
Lớp
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Kể từ phiên bản 2.0

mục lục

seq_of_parameters

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Danh mục ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, danh mục mặc định, thường là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
9, sẽ được sử dụng].
access_token5 parameter.

mục lục

Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Danh mục ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, danh mục mặc định, thường là
from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
9, sẽ được sử dụng].

  • lược đồ

lược đồ

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học

Lớp
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

Đại diện cho một kết nối với một cơ sở dữ liệu.

  • Phương pháp
  • Phương pháp
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    5

Lược đồ ban đầu để sử dụng cho kết nối. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3 [trong trường hợp đó, lược đồ mặc định pip install databricks-sql-connector2 sẽ được sử dụng].

Các lớp học

Các lớp học
catalog_name

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Lớp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
7

Tham số này là tùy chọn.

schema_name

Các cặp bổ sung [khóa, giá trị] để đặt trong các tiêu đề HTTP trên mỗi yêu cầu RPC mà máy khách thực hiện. Sử dụng điển hình sẽ không đặt bất kỳ tiêu đề HTTP bổ sung nào. Mặc định là

from databricks import sql
import os, logging

logging.getLogger["databricks.sql"].setLevel[logging.DEBUG]
logging.basicConfig[filename = "results.log",
                    level    = logging.DEBUG]

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]

result = cursor.fetchall[]

for row in result:
   logging.debug[row]

cursor.close[]
connection.close[]
3.

Đại diện cho một kết nối với một cơ sở dữ liệu.

Tham số này là tùy chọn.

Phương pháp

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
5

  • Tên trường:
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    06. Loại:
    from databricks import sql
    import os
    
    connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                             http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                             access_token    = os.getenv["DATABRICKS_TOKEN"]]
    
    cursor = connection.cursor[]
    
    cursor.execute["SELECT * from range[10]"]
    print[cursor.fetchall[]]
    
    cursor.close[]
    connection.close[]
    
    3. Danh mục mà bảng thuộc về.
  • Tên trường:
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    11. Loại:
    from databricks import sql
    import os
    
    connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                             http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                             access_token    = os.getenv["DATABRICKS_TOKEN"]]
    
    cursor = connection.cursor[]
    
    cursor.execute["SELECT * from range[10]"]
    print[cursor.fetchall[]]
    
    cursor.close[]
    connection.close[]
    
    3. Lược đồ mà bảng thuộc về.
  • Tên trường:
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    26. Loại:
    from databricks import sql
    import os
    
    connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                             http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                             access_token    = os.getenv["DATABRICKS_TOKEN"]]
    
    cursor = connection.cursor[]
    
    cursor.execute["SELECT * from range[10]"]
    print[cursor.fetchall[]]
    
    cursor.close[]
    connection.close[]
    
    3. Tên của cái bàn.
  • Tên trường:
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    28. Loại:
    from databricks import sql
    import os
    
    connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                             http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                             access_token    = os.getenv["DATABRICKS_TOKEN"]]
    
    cursor = connection.cursor[]
    
    cursor.execute["SELECT * from range[10]"]
    print[cursor.fetchall[]]
    
    cursor.close[]
    connection.close[]
    
    3. Loại quan hệ, ví dụ
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    30 hoặc
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    31 [áp dụng cho Databricks RunTime 10.2 trở lên cũng như cho Databricks SQL; các phiên bản trước của thời gian chạy Databricks trả về một chuỗi trống].

Không có giá trị trả về.

Kể từ phiên bản 1.0

Thông số
catalog_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

schema_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

table_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

table_types

Một tên lược đồ để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Một tên bảng để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

Một tên lược đồ để truy xuất thông tin về. Nhân vật
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Một tên bảng để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

  • Loại:
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    38
  • Một danh sách các loại bảng để khớp, ví dụ
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    31 hoặc
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    30.
  • Phương pháp
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.columns[schema_name="default", table_name="squares"]
        print[cursor.fetchall[]]
    
    0
  • Thực hiện truy vấn siêu dữ liệu về các cột. Kết quả thực tế sau đó nên được tìm nạp bằng
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.columns[schema_name="default", table_name="squares"]
        print[cursor.fetchall[]]
    
    2 hoặc
    from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.columns[schema_name="default", table_name="squares"]
        print[cursor.fetchall[]]
    
    1. Các trường quan trọng trong tập kết quả bao gồm:

Không có giá trị trả về.

Kể từ phiên bản 1.0

Thông số
catalog_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

schema_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

table_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

column_name

Loại:

from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

Một tên lược đồ để truy xuất thông tin về. Nhân vật
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Một tên bảng để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Loại:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
38

Một danh sách các loại bảng để khớp, ví dụ

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
31 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
30.

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
0

Thực hiện truy vấn siêu dữ liệu về các cột. Kết quả thực tế sau đó nên được tìm nạp bằng
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
2 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
1. Các trường quan trọng trong tập kết quả bao gồm:

Tên trường:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
06. Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3. Danh mục mà cột thuộc về.

Tên trường:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
11. Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3. Lược đồ mà cột thuộc về.

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
0

Thông số
Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

Một tên lược đồ để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Một tên bảng để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Loại:
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
38

Một danh sách các loại bảng để khớp, ví dụ

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
31 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
30.

Loại:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
38

Một danh sách các loại bảng để khớp, ví dụ

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
31 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
30.

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
0

Thực hiện truy vấn siêu dữ liệu về các cột. Kết quả thực tế sau đó nên được tìm nạp bằng
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
2 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
1. Các trường quan trọng trong tập kết quả bao gồm:

Tên trường:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
06. Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3. Danh mục mà cột thuộc về.

Loại:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
38

Một danh sách các loại bảng để khớp, ví dụ

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
31 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
30.

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
0

Thực hiện truy vấn siêu dữ liệu về các cột. Kết quả thực tế sau đó nên được tìm nạp bằng

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
2 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
1. Các trường quan trọng trong tập kết quả bao gồm:

Tên trường:
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
06. Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3. Danh mục mà cột thuộc về.

Tên trường:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
11. Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3. Lược đồ mà cột thuộc về.

Tên trường:

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
26. Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3. Tên của bảng mà cột thuộc về.

Phương pháp

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
0

Thực hiện truy vấn siêu dữ liệu về các cột. Kết quả thực tế sau đó nên được tìm nạp bằng

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
2 hoặc
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
1. Các trường quan trọng trong tập kết quả bao gồm:

Thông số
Loại:
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3

Một tên danh mục để lấy thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Tham số này là tùy chọn.

Một tên lược đồ để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Một tên bảng để truy xuất thông tin về. Nhân vật

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
16 được hiểu là ký tự đại diện.

Loại:
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
38

Lớp hàng là một cấu trúc dữ liệu giống như tuple đại diện cho một hàng kết quả riêng lẻ. Nếu hàng chứa một cột có tên

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
97, bạn có thể truy cập vào trường
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
97 của
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
99 qua
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
00. Bạn cũng có thể sử dụng các chỉ số số để truy cập các trường, ví dụ
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
01. Nếu tên cột không được phép làm tên phương thức thuộc tính [ví dụ: nó bắt đầu bằng một chữ số], thì bạn có thể truy cập trường là
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
02.

Kể từ phiên bản 1.0

Phương phápPhương pháp
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.columns[schema_name="default", table_name="squares"]
    print[cursor.fetchall[]]
7

Trả về một biểu diễn từ điển của hàng, được lập chỉ mục bởi các tên trường. Nếu có tên trường trùng lặp, một trong các trường trùng lặp [nhưng chỉ có một] sẽ được trả lại trong từ điển. Trường nào được trả lại không được xác định.

Không có tham số.

Trả về

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["SELECT * FROM default.diamonds LIMIT 2"]
    result = cursor.fetchall[]

    for row in result:
      print[row]
01 của các trường.

Nhập chuyển đổi

Bảng sau đây ánh xạ các loại dữ liệu SQL Apache Spark vào các loại tương đương loại dữ liệu Python của chúng.

Kiểu dữ liệu Apache Spark SQLKiểu dữ liệu Python
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
05
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
07
server_hostname7
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
09
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
10
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
11
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
12
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
13
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
14
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
15
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
16
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
17
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
18
server_hostname7server_hostname7
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
09
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
07
server_hostname7
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
09
server_hostname7
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
09
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
07
from databricks import sql
import os

connection = sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                         http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                         access_token    = os.getenv["DATABRICKS_TOKEN"]]

cursor = connection.cursor[]

cursor.execute["SELECT * from range[10]"]
print[cursor.fetchall[]]

cursor.close[]
connection.close[]
3
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
07
server_hostname7
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
09
server_hostname7

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
09

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
10

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
11: When you run your code, you see a message similar to
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
36.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
12: The value passed to access_token is not a valid Azure Databricks personal access token.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
13: Check that the value passed to access_token is correct and try again.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
14

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
15: When you run your code, you see a message similar to
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
40.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
16: The value passed to server_hostname is not the correct host name.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
17: Check that the value passed to server_hostname is correct and try again.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
18

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
21

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
23: When you run your code, you see the message
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
44 when you try to use the connector on an Azure Databricks notebook.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
24: You may have IP allow listing enabled for the Azure Databricks workspace. With IP allow listing, connections from Spark clusters back to the control plane are not allowed by default.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
25: Ask your administrator to add the data plane subnet to the IP allow list.

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
27

from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
29

  • from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]
    
        squares = [[i, i * i] for i in range[100]]
        values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]
    
        cursor.execute[f"INSERT INTO squares VALUES {values}"]
    
        cursor.execute["SELECT * FROM squares LIMIT 10"]
    
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    31
  • from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]
    
        squares = [[i, i * i] for i in range[100]]
        values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]
    
        cursor.execute[f"INSERT INTO squares VALUES {values}"]
    
        cursor.execute["SELECT * FROM squares LIMIT 10"]
    
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    32
  • from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]
    
        squares = [[i, i * i] for i in range[100]]
        values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]
    
        cursor.execute[f"INSERT INTO squares VALUES {values}"]
    
        cursor.execute["SELECT * FROM squares LIMIT 10"]
    
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    33
  • Xử lý sự cố
  • from databricks import sql
    import os
    
    with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                     http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                     access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:
    
      with connection.cursor[] as cursor:
        cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]
    
        squares = [[i, i * i] for i in range[100]]
        values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]
    
        cursor.execute[f"INSERT INTO squares VALUES {values}"]
    
        cursor.execute["SELECT * FROM squares LIMIT 10"]
    
        result = cursor.fetchall[]
    
        for row in result:
          print[row]
    
    35 Tin nhắn

Vấn đề: Khi bạn chạy mã của mình, bạn sẽ thấy một thông báo tương tự như
from databricks import sql
import os

with sql.connect[server_hostname = os.getenv["DATABRICKS_SERVER_HOSTNAME"],
                 http_path       = os.getenv["DATABRICKS_HTTP_PATH"],
                 access_token    = os.getenv["DATABRICKS_TOKEN"]] as connection:

  with connection.cursor[] as cursor:
    cursor.execute["CREATE TABLE IF NOT EXISTS squares [x int, x_squared int]"]

    squares = [[i, i * i] for i in range[100]]
    values = ",".join[[f"[{x}, {y}]" for [x, y] in squares]]

    cursor.execute[f"INSERT INTO squares VALUES {values}"]

    cursor.execute["SELECT * FROM squares LIMIT 10"]

    result = cursor.fetchall[]

    for row in result:
      print[row]
36.

Nguyên nhân có thể: Giá trị được chuyển cho access_token không phải là mã thông báo truy cập cá nhân Azure Databricks hợp lệ.

Chúng ta có thể sử dụng biến Python trong truy vấn SQL không?

Chúng ta thường cần chuyển các biến cho SQL Chọn truy vấn trong mệnh đề WHERE để kiểm tra một số điều kiện. Trong biểu mẫu đăng ký người dùng, người dùng nhập chi tiết của anh ấy/cô ấy. Bạn có thể lấy các giá trị đó trong các biến Python và chèn chúng vào một bảng.You can take those values in Python variables and insert them into a table.

Làm thế nào để bạn chuyển một biến python cho truy vấn SQL trong pyspark?

Bạn có thể chuyển các tham số/đối số cho các câu lệnh SQL của mình bằng cách tạo chuỗi SQL bằng cách sử dụng scala/python và chuyển nó sang sqlcontext ...
Tham số của bạn.val p1 = "['0001', '0002', '0003']" ....
Xây dựng truy vấn.....
Sau đó, bạn có thể truy vấn nó ..

Làm thế nào để bạn khai báo một biến trong Databricks?

Đây là một chút của nồi hơi, nhưng nó hoạt động như thế này:..
Nhập mô -đun TensorFlow và gọi nó là TF ..
Tạo một giá trị không đổi gọi là X và cho nó giá trị số 35 ..
Tạo một biến gọi là y và định nghĩa nó là phương trình x + 5 ..
Khởi tạo các biến với TF.....
Tạo một phiên để tính toán các giá trị ..

Chúng ta có thể sử dụng các biến trong Spark SQL không?

Câu trả lời ngắn gọn là không, hiện tại Spark SQL không hỗ trợ các biến.Máy chủ SQL sử dụng T-SQL, dựa trên tiêu chuẩn SQL được mở rộng với lập trình thủ tục, các biến cục bộ và các tính năng khác.Spark SQL là SQL thuần túy, tương thích một phần với tiêu chuẩn SQL.no, Spark SQL does not support variables currently. The SQL Server uses T-SQL, which is based on SQL standard extended with procedure programming, local variables and other features. Spark SQL is a pure SQL, partially compatible with SQL standard.

Bài Viết Liên Quan

Chủ Đề