Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove databricks session spark object #129

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ History
=======


v0.20.16 (2024-03-19)

* Remove databricks session spark object and use original method to convert spark to polars df.


v0.20.15 (2024-03-16)

* Explicitly add databricks config to DatabricksSession.
Expand Down
13 changes: 3 additions & 10 deletions aioradio/ds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import numpy as np
import pandas as pd
import polars as pl
import pyarrow as pa
from haversine import haversine, Unit
from mlflow.entities.model_registry.model_version_status import ModelVersionStatus
from mlflow.tracking.client import MlflowClient
Expand All @@ -48,15 +49,7 @@
c_handler.setFormatter(c_format)
logger.addHandler(c_handler)

try:
from databricks.connect import DatabricksSession
spark = DatabricksSession.builder.remote(
host=os.environ['DATABRICKS_HOST'],
token=os.environ['DATABRICKS_TOKEN'],
cluster_id=os.environ['DATABRICKS_CLUSTER_ID']
).getOrCreate()
except Exception:
spark = SparkSession.builder.getOrCreate()
spark = SparkSession.builder.getOrCreate()


############################### Databricks functions ################################
Expand Down Expand Up @@ -91,7 +84,7 @@ def ese_db_catalog(env):
def sql_to_polars_df(sql):
"""Get polars DataFrame from SQL query results."""

return pl.from_pandas(spark.sql(sql).toPandas())
return pl.from_arrow(pa.Table.from_batches(spark.sql(sql)._collect_as_arrow()))


def does_db_table_exists(name):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = fileobj.read()

setup(name='aioradio',
version='0.20.15',
version='0.20.16',
description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
Loading