-
Notifications
You must be signed in to change notification settings - Fork 2
Update benchmark to work with Databricks #19
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
Open
crcarreras
wants to merge
1
commit into
main
Choose a base branch
from
connor-databricks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,643
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
DROP AGGREGATING INDEX IF EXISTS idx_by_day; | ||
DROP TABLE IF EXISTS uservisits; | ||
DROP TABLE IF EXISTS rankings; | ||
DROP TABLE IF EXISTS ipaddresses; | ||
DROP TABLE IF EXISTS agents; | ||
DROP TABLE IF EXISTS searchwords; | ||
|
||
CREATE TABLE "uservisits" ("sourceip" text NOT NULL, | ||
"destinationurl" text NOT NULL, | ||
"visitdate" pgdate NOT NULL, | ||
"adrevenue" REAL NOT NULL, | ||
"useragent" text NOT NULL, | ||
"countrycode" text NOT NULL, | ||
"languagecode" text NOT NULL, | ||
"searchword" text NOT NULL, | ||
"duration" integer NOT NULL) | ||
PRIMARY INDEX "visitdate", "destinationurl", "sourceip"; | ||
|
||
CREATE TABLE "ipaddresses" ("ip" text NOT NULL, | ||
"autonomoussystem" integer NOT NULL, | ||
"asname" text NOT NULL) | ||
PRIMARY INDEX "ip"; | ||
|
||
CREATE TABLE "rankings" ("pageurl" text NOT NULL, | ||
"pagerank" integer NULL, | ||
"avgduration" integer NOT NULL) | ||
PRIMARY INDEX "pageurl"; | ||
|
||
CREATE TABLE "agents" ("id" integer NOT NULL, | ||
"agentname" text NOT NULL, | ||
"operatingsystem" text NOT NULL, | ||
"devicearch" text NOT NULL, | ||
"browser" text NOT NULL); | ||
|
||
CREATE TABLE "searchwords" ("word" text NOT NULL, | ||
"word_hash" bigint NOT NULL, | ||
"word_id" bigint NOT NULL, | ||
"firstseen" pgdate NOT NULL, | ||
"is_topic" boolean NOT NULL); | ||
|
||
COPY | ||
INTO | ||
uservisits | ||
FROM | ||
's3://firebolt-benchmarks-requester-pays-us-east-1/firenewt/1tb/uservisits/gz-parquet/' | ||
WITH | ||
CREDENTIALS = (AWS_ROLE_ARN = 'arn:aws:iam::442042532160:role/FireboltS3DatasetsAccess') | ||
TYPE = parquet; | ||
|
||
COPY | ||
INTO | ||
rankings | ||
FROM | ||
's3://firebolt-benchmarks-requester-pays-us-east-1/firenewt/1tb/rankings/' | ||
WITH | ||
CREDENTIALS = (AWS_ROLE_ARN = 'arn:aws:iam::442042532160:role/FireboltS3DatasetsAccess') | ||
TYPE = parquet; | ||
|
||
COPY | ||
INTO | ||
ipaddresses | ||
FROM | ||
's3://firebolt-benchmarks-requester-pays-us-east-1/firenewt/1tb/dimensions/ipaddresses/' | ||
WITH | ||
CREDENTIALS = (AWS_ROLE_ARN = 'arn:aws:iam::442042532160:role/FireboltS3DatasetsAccess') | ||
TYPE = parquet; | ||
|
||
COPY | ||
INTO | ||
agents | ||
FROM | ||
's3://firebolt-benchmarks-requester-pays-us-east-1/firenewt/1tb/dimensions/agents/' | ||
WITH | ||
CREDENTIALS = (AWS_ROLE_ARN = 'arn:aws:iam::442042532160:role/FireboltS3DatasetsAccess') | ||
TYPE = parquet; | ||
|
||
COPY | ||
INTO | ||
searchwords | ||
FROM | ||
's3://firebolt-benchmarks-requester-pays-us-east-1/firenewt/1tb/dimensions/searchwords/' | ||
WITH | ||
CREDENTIALS = (AWS_ROLE_ARN = 'arn:aws:iam::442042532160:role/FireboltS3DatasetsAccess') | ||
TYPE = parquet; | ||
|
||
VACUUM uservisits; | ||
|
||
VACUUM uservisits; | ||
|
||
VACUUM rankings; | ||
|
||
VACUUM searchwords; | ||
|
||
VACUUM agents; | ||
|
||
VACUUM ipaddresses; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from databricks import sql | ||
from typing import Any, Dict, Optional, List | ||
|
||
class DatabricksConnector: | ||
def __init__(self, config: Dict[str, str]): | ||
""" | ||
Initialize Databricks connector with configuration parameters. | ||
|
||
Args: | ||
config (Dict[str, str]): Configuration dictionary containing: | ||
"server_hostname": "your sql warehouse hostname", | ||
"http_path": "http path for warehouse", | ||
"access_token": "your databricks personal access token", | ||
"catalog": "Databricks warehouse name", | ||
"schema": "Databricks schema name" | ||
""" | ||
self.config = config | ||
self._validate_config() | ||
self._conn = None | ||
self.cursor = None | ||
|
||
def _validate_config(self) -> None: | ||
"""Validate that required configuration parameters are present.""" | ||
required_params = ['server_hostname', 'http_path', 'access_token', 'catalog', 'schema'] | ||
missing_params = [param for param in required_params if param not in self.config] | ||
if missing_params: | ||
raise ValueError(f"Missing required configuration parameters: {missing_params}") | ||
|
||
def connect(self) -> None: | ||
"""Connect to Databricks using stored configuration.""" | ||
if not self._conn: | ||
self._conn = sql.connect( | ||
server_hostname=self.config['server_hostname'], | ||
http_path=self.config['http_path'], | ||
access_token=self.config['access_token'], | ||
catalog=self.config['catalog'], | ||
schema=self.config['schema'] | ||
) | ||
self.cursor = self._conn.cursor() | ||
self.cursor.execute("SET use_cached_result = false;") | ||
|
||
def execute_query(self, query: str, params: Optional[Dict[str, Any]] = None) -> List[Dict]: | ||
""" | ||
Execute a SQL query and return results as a list of dictionaries. | ||
|
||
Args: | ||
query (str): SQL query to execute | ||
params (Optional[Dict[str, Any]]): Query parameters for parameterized queries | ||
|
||
Returns: | ||
List[Dict]: Query results as a list of dictionaries | ||
""" | ||
if not self._conn or not self.cursor: | ||
self.connect() | ||
|
||
try: | ||
self.cursor.execute(query, params or {}) | ||
return self.cursor.fetchall() | ||
except Exception as e: | ||
raise Exception(f"Error executing query: {str(e)}") | ||
|
||
def close(self) -> None: | ||
"""Close the Databricks connection if it exists.""" | ||
if self._conn: | ||
self._conn.close() | ||
self._conn = None | ||
self.cursor = None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you VACUUM in Databricks / have you validated that this setup file works for Databricks?