Skip to content

Commit 4181c0a

Browse files
authored
Merge pull request #32 from stackql/feature/updates
v3.5.3
2 parents e3df5ca + 0b13419 commit 4181c0a

File tree

7 files changed

+40
-21
lines changed

7 files changed

+40
-21
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v3.5.3 (2024-04-08)
4+
5+
### Updates
6+
7+
* added `backend_storage_mode` and `backend_file_storage_location` constructor args for specifying a file based backend (not applicable in `server_mode`)
8+
39
## v3.5.2 (2024-03-21)
410

511
### Updates

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Before testing, ensure you have all the required packages installed:
161161
::
162162

163163
pip install -r requirements.txt
164+
pip install psycopg2-binary
164165

165166
Once the dependencies are installed, you can run the tests using the provided script:
166167

@@ -193,4 +194,4 @@ To publish the package to PyPI, run the following command:
193194

194195
::
195196

196-
twine upload dist/pystackql-3.5.2.tar.gz
197+
twine upload dist/pystackql-3.5.3.tar.gz

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
# -- Project information -----------------------------------------------------
2121

2222
project = 'pystackql'
23-
copyright = '2024, StackQL Studios'
23+
copyright = '2021-2024, StackQL Studios'
2424
author = 'StackQL Studios'
2525

2626
# The short X.Y version
2727
version = ''
2828
# The full version, including alpha/beta/rc tags
29-
release = '3.5.2'
29+
release = '3.5.3'
3030

3131

3232
# -- General configuration ---------------------------------------------------

pystackql/stackql.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ class StackQL:
2626
:param server_port: The port of the StackQL server
2727
(`server_mode` only, defaults to `5466`)
2828
:type server_port: int, optional
29+
:param backend_storage_mode: Specifies backend storage mode, options are 'memory' and 'file'
30+
(defaults to `'memory'`, this option is ignored in `server_mode`)
31+
:type backend_storage_mode: str, optional
32+
:param backend_file_storage_location: Specifies location for database file, only applicable when `backend_storage_mode` is 'file'
33+
(defaults to `'{cwd}/stackql.db'`, this option is ignored in `server_mode`)
34+
:type backend_file_storage_location: str, optional
2935
:param output: Determines the format of the output, options are 'dict', 'pandas', and 'csv'
3036
(defaults to `'dict'`, `'csv'` is not supported in `server_mode`)
3137
:type output: str, optional
@@ -210,7 +216,9 @@ def _run_query(self, query):
210216
def __init__(self,
211217
server_mode=False,
212218
server_address='127.0.0.1',
213-
server_port=5466,
219+
server_port=5466,
220+
backend_storage_mode='memory',
221+
backend_file_storage_location='stackql.db',
214222
download_dir=None,
215223
app_root=None,
216224
execution_concurrency_limit=1,
@@ -284,7 +292,12 @@ def __init__(self,
284292
self.params.append("csv")
285293
else:
286294
self.params.append("json")
287-
295+
296+
# backend storage settings
297+
if backend_storage_mode == 'file':
298+
self.params.append("--sqlBackend")
299+
self.params.append(json.dumps({ "dsn": f"file:{backend_file_storage_location}" }))
300+
288301
# get or download the stackql binary
289302
binary = _get_binary_name(this_os)
290303

@@ -330,10 +343,8 @@ def __init__(self,
330343
# if custom_registry is set, use it
331344
if custom_registry is not None:
332345
self.custom_registry = custom_registry
333-
custom_reg_obj = { "url": custom_registry }
334-
custom_reg_str = json.dumps(custom_reg_obj)
335346
self.params.append("--registry")
336-
self.params.append(custom_reg_str)
347+
self.params.append(json.dumps({ "url": custom_registry }))
337348

338349
# csv output
339350
if self.output == "csv":

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name='pystackql',
13-
version='3.5.2',
13+
version='3.5.3',
1414
description='A Python interface for StackQL',
1515
long_description=readme,
1616
author='Jeffrey Aven',

tests/pystackql_tests.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def setUpModule():
4141
print("downloading aws provider for tests...")
4242
res = PyStackQLTestsBase.stackql.executeStmt(registry_pull_aws_query)
4343
print(res)
44+
print("downloading awscc provider for tests...")
45+
res = PyStackQLTestsBase.stackql.executeStmt(registry_pull_awscc_query)
46+
print(res)
4447
print("downloading google provider for tests...")
4548
res = PyStackQLTestsBase.stackql.executeStmt(registry_pull_google_query)
4649
print(res)
@@ -201,8 +204,8 @@ def test_12_execute_with_pandas_output(self):
201204
self.assertTrue(is_valid_dataframe, f"Result is not a valid DataFrame: {result}")
202205
# Check datatypes of the columns
203206
expected_dtypes = {
204-
'instance_state': 'object', # This should be 'object' for older Pandas versions
205-
'num_instances': 'int64'
207+
'year': 'int64',
208+
'num_buckets': 'int64'
206209
}
207210
for col, expected_dtype in expected_dtypes.items():
208211
actual_dtype = result[col].dtype
@@ -280,8 +283,8 @@ def test_22_execute_server_mode_pandas_output(self):
280283
self.assertTrue(is_valid_dataframe, f"Result is not a valid DataFrame: {result}")
281284
# Check datatypes of the columns
282285
expected_dtypes = {
283-
'instance_state': 'object', # This should be 'object' for older Pandas versions
284-
'num_instances': 'int64'
286+
'year': 'int64',
287+
'num_buckets': 'int64'
285288
}
286289
for col, expected_dtype in expected_dtypes.items():
287290
actual_dtype = result[col].dtype

tests/test_params.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def get_custom_download_dir(platform_name):
2727

2828
registry_pull_google_query = "REGISTRY PULL google"
2929
registry_pull_aws_query = "REGISTRY PULL aws"
30+
registry_pull_awscc_query = "REGISTRY PULL awscc"
3031
registry_pull_okta_query = "REGISTRY PULL okta"
3132
registry_pull_github_query = "REGISTRY PULL github"
3233

@@ -43,21 +44,18 @@ def registry_pull_resp_pattern(provider):
4344

4445
aws_query = f"""
4546
SELECT
46-
split_part(instanceState, '\n', 3) as instance_state,
47-
count(*) as num_instances
48-
FROM aws.ec2.instances
49-
WHERE region = '{os.environ['AWS_REGION']}'
50-
GROUP BY instance_state
47+
SPLIT_PART(CreationDate, '-', 1) as year, count(*) as num_buckets FROM aws.s3.buckets
48+
WHERE region = 'us-east-1'
49+
GROUP BY year
5150
"""
5251

5352
regions = os.environ.get('AWS_REGIONS').split(',')
5453

5554
async_queries = [
5655
f"""
57-
SELECT '{region}' as region, instanceType, COUNT(*) as num_instances
58-
FROM aws.ec2.instances
56+
SELECT region, COUNT(*) as num_functions
57+
FROM awscc.lambda.functions
5958
WHERE region = '{region}'
60-
GROUP BY instanceType
6159
"""
6260
for region in regions
6361
]

0 commit comments

Comments
 (0)