sqlalchemy-bigquery 0.0.1dev__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sqlalchemy_bigquery-0.0.4/MANIFEST.in +1 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/PKG-INFO +39 -43
- sqlalchemy_bigquery-0.0.4/README.rst +61 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/setup.cfg +1 -1
- sqlalchemy_bigquery-0.0.4/setup.py +41 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery/__init__.py +1 -1
- sqlalchemy_bigquery-0.0.4/sqlalchemy_bigquery/base.py +71 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/PKG-INFO +39 -43
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/SOURCES.txt +1 -1
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/test/test_suite.py +24 -1
- sqlalchemy_bigquery-0.0.1dev/MANIFEST.in +0 -1
- sqlalchemy_bigquery-0.0.1dev/README.md +0 -65
- sqlalchemy_bigquery-0.0.1dev/setup.py +0 -40
- sqlalchemy_bigquery-0.0.1dev/sqlalchemy_bigquery/base.py +0 -32
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery/pyodbc.py +0 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery/requirements.py +0 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/dependency_links.txt +0 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/entry_points.txt +0 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/not-zip-safe +0 -0
- {sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include README.rst
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: sqlalchemy_bigquery
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: BigQuery for SQLAlchemy
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: Conrad Dean
|
|
@@ -26,51 +26,47 @@ Description: BigQuery dialect for SQLAlchemy.
|
|
|
26
26
|
in a regular service call.
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
To Install
|
|
29
|
+
To Install::
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
pip install sqlalchemy-bigquery
|
|
33
|
-
```
|
|
31
|
+
pip install sqlalchemy-bigquery
|
|
34
32
|
|
|
35
|
-
Usage Example
|
|
33
|
+
Usage Example::
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
FROM [fruit.table] GROUP BY fruit_type
|
|
73
|
-
```
|
|
35
|
+
>>> import sqlalchemy.sql as sql
|
|
36
|
+
>>>
|
|
37
|
+
>>> from sqlalchemy import func
|
|
38
|
+
>>> import sqlalchemy_bigquery.base as bq
|
|
39
|
+
>>>
|
|
40
|
+
>>>
|
|
41
|
+
>>> country = sql.column("country")
|
|
42
|
+
>>> fruit_type = sql.column("fruit_type")
|
|
43
|
+
>>> calories = sql.column("calories")
|
|
44
|
+
>>> total_usa = func.sum(
|
|
45
|
+
... sql.case(
|
|
46
|
+
... [(country == "usa", 1)],
|
|
47
|
+
... else_=0
|
|
48
|
+
... )
|
|
49
|
+
... ).label("Total_in_USA")
|
|
50
|
+
>>> total_japan = func.sum(
|
|
51
|
+
... sql.case(
|
|
52
|
+
... [(country == "japan", 1)],
|
|
53
|
+
... else_=0
|
|
54
|
+
... )
|
|
55
|
+
... ).label("Total_in_Japan")
|
|
56
|
+
>>> s = sql.select([
|
|
57
|
+
... fruit_type,
|
|
58
|
+
... total_usa,
|
|
59
|
+
... total_japan,
|
|
60
|
+
... ]).select_from(sql.table("fruit.table")
|
|
61
|
+
... ).group_by(
|
|
62
|
+
... fruit_type
|
|
63
|
+
... ).compile(
|
|
64
|
+
... compile_kwargs={"literal_binds": True},
|
|
65
|
+
... dialect=bq.BQDialect()
|
|
66
|
+
... )
|
|
67
|
+
>>> print str(s)
|
|
68
|
+
SELECT fruit_type, sum(CASE WHEN (country = 'usa') THEN 1 ELSE 0 END) AS Total_in_USA, sum(CASE WHEN (country = 'japan') THEN 1 ELSE 0 END) AS Total_in_Japan
|
|
69
|
+
FROM [fruit.table] GROUP BY fruit_type
|
|
74
70
|
|
|
75
71
|
Keywords: SQLAlchemy Google BigQuery
|
|
76
72
|
Platform: UNKNOWN
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
BigQuery dialect for SQLAlchemy.
|
|
2
|
+
|
|
3
|
+
BigQuery implements a DSL that is similar to SQL with a few quirks:
|
|
4
|
+
|
|
5
|
+
1. It has a "group each by" hint for grouping over large amounts of data
|
|
6
|
+
2. You need to use the "join each ... on" form when joining on a table larger than a small number of megabytes.
|
|
7
|
+
3. You can't quote columns, but you can quote tables. But probably not table aliasess.
|
|
8
|
+
4. Because you can't quote columns, you are limited to colums with no spaces, only alpha-numeric characters with underscores, and you can only start a column with a letter or underscore
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
The first two issues (the non-standard "each" modifier for grouping and joining) has not been addressed yet. BigQuery pushes the responsibility of when to recognize a table is too big for certain operations, and shifts burden onto you when you want to use those modifiers. Sometimes you need them, sometimes you don't. Leaving this as an exercise to the user to just string replace those out of what this dialect returns.
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Usage
|
|
15
|
+
|
|
16
|
+
There currently isn't support for using sqlalchemy to connect to
|
|
17
|
+
BigQuery. Currently there's only support for generating SQL to send
|
|
18
|
+
in a regular service call.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
To Install::
|
|
22
|
+
|
|
23
|
+
pip install sqlalchemy-bigquery
|
|
24
|
+
|
|
25
|
+
Usage Example::
|
|
26
|
+
|
|
27
|
+
>>> import sqlalchemy.sql as sql
|
|
28
|
+
>>>
|
|
29
|
+
>>> from sqlalchemy import func
|
|
30
|
+
>>> import sqlalchemy_bigquery.base as bq
|
|
31
|
+
>>>
|
|
32
|
+
>>>
|
|
33
|
+
>>> country = sql.column("country")
|
|
34
|
+
>>> fruit_type = sql.column("fruit_type")
|
|
35
|
+
>>> calories = sql.column("calories")
|
|
36
|
+
>>> total_usa = func.sum(
|
|
37
|
+
... sql.case(
|
|
38
|
+
... [(country == "usa", 1)],
|
|
39
|
+
... else_=0
|
|
40
|
+
... )
|
|
41
|
+
... ).label("Total_in_USA")
|
|
42
|
+
>>> total_japan = func.sum(
|
|
43
|
+
... sql.case(
|
|
44
|
+
... [(country == "japan", 1)],
|
|
45
|
+
... else_=0
|
|
46
|
+
... )
|
|
47
|
+
... ).label("Total_in_Japan")
|
|
48
|
+
>>> s = sql.select([
|
|
49
|
+
... fruit_type,
|
|
50
|
+
... total_usa,
|
|
51
|
+
... total_japan,
|
|
52
|
+
... ]).select_from(sql.table("fruit.table")
|
|
53
|
+
... ).group_by(
|
|
54
|
+
... fruit_type
|
|
55
|
+
... ).compile(
|
|
56
|
+
... compile_kwargs={"literal_binds": True},
|
|
57
|
+
... dialect=bq.BQDialect()
|
|
58
|
+
... )
|
|
59
|
+
>>> print str(s)
|
|
60
|
+
SELECT fruit_type, sum(CASE WHEN (country = 'usa') THEN 1 ELSE 0 END) AS Total_in_USA, sum(CASE WHEN (country = 'japan') THEN 1 ELSE 0 END) AS Total_in_Japan
|
|
61
|
+
FROM [fruit.table] GROUP BY fruit_type
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import re
|
|
3
|
+
|
|
4
|
+
from setuptools import setup
|
|
5
|
+
|
|
6
|
+
v = open(os.path.join(os.path.dirname(__file__), 'sqlalchemy_bigquery', '__init__.py'))
|
|
7
|
+
VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(v.read()).group(1)
|
|
8
|
+
v.close()
|
|
9
|
+
|
|
10
|
+
readme = os.path.join(os.path.dirname(__file__), 'README.rst')
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
setup(
|
|
14
|
+
name='sqlalchemy_bigquery',
|
|
15
|
+
version=VERSION,
|
|
16
|
+
description="BigQuery for SQLAlchemy",
|
|
17
|
+
long_description=open(readme).read(),
|
|
18
|
+
classifiers=[
|
|
19
|
+
'Development Status :: 3 - Alpha',
|
|
20
|
+
'Environment :: Console',
|
|
21
|
+
'Intended Audience :: Developers',
|
|
22
|
+
'Programming Language :: Python',
|
|
23
|
+
'Programming Language :: Python :: 3',
|
|
24
|
+
'Programming Language :: Python :: Implementation :: CPython',
|
|
25
|
+
'Topic :: Database :: Front-Ends',
|
|
26
|
+
],
|
|
27
|
+
keywords='SQLAlchemy Google BigQuery',
|
|
28
|
+
author='Conrad Dean',
|
|
29
|
+
author_email='conrad.p.dean@gmail.com',
|
|
30
|
+
license='MIT',
|
|
31
|
+
packages=['sqlalchemy_bigquery'],
|
|
32
|
+
include_package_data=True,
|
|
33
|
+
tests_require=['py.test'],
|
|
34
|
+
zip_safe=False,
|
|
35
|
+
entry_points={
|
|
36
|
+
'sqlalchemy.dialects': [
|
|
37
|
+
'bigquery = sqlalchemy_bigquery.pyodbc:BigQueryDialect_pyodbc',
|
|
38
|
+
'bigquery.pyodbc = sqlalchemy_bigquery.pyodbc:BigQueryDialect_pyodbc',
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Support for Google BigQuery.
|
|
3
|
+
|
|
4
|
+
Does not support actually connecting to BQ.
|
|
5
|
+
Directly derived from the mssql dialect with minor modifications
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
import sqlalchemy.dialects.mssql.base as mssql_base
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
from sqlalchemy.dialects.mssql.base import MSDialect
|
|
12
|
+
from sqlalchemy.sql import compiler
|
|
13
|
+
from sqlalchemy.sql import sqltypes
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BQString(sqltypes.String):
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
length=None,
|
|
20
|
+
collation=None,
|
|
21
|
+
convert_unicode=False,
|
|
22
|
+
unicode_error=None,
|
|
23
|
+
_warn_on_bytestring=False
|
|
24
|
+
):
|
|
25
|
+
return super(BQString, self).__init__(
|
|
26
|
+
length=length,
|
|
27
|
+
collation=collation,
|
|
28
|
+
convert_unicode=convert_unicode,
|
|
29
|
+
unicode_error=unicode_error,
|
|
30
|
+
_warn_on_bytestring=_warn_on_bytestring
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def literal_processor(self, dialect):
|
|
34
|
+
def process(value):
|
|
35
|
+
value = value.replace("'", "\'")
|
|
36
|
+
return "'%s'" % value
|
|
37
|
+
return process
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class BQSQLCompiler(mssql_base.MSSQLCompiler):
|
|
41
|
+
|
|
42
|
+
def visit_column(self, column, add_to_result_map=None, **kwargs):
|
|
43
|
+
# TODO: figure out how to do this immutably
|
|
44
|
+
# force column rendering to not use quotes by declaring every col literal
|
|
45
|
+
column.is_literal = True
|
|
46
|
+
return super(BQSQLCompiler, self).visit_column(
|
|
47
|
+
column,
|
|
48
|
+
add_to_result_map=add_to_result_map,
|
|
49
|
+
**kwargs
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class BQIdentifierPreparer(compiler.IdentifierPreparer):
|
|
54
|
+
def __init__(self, dialect):
|
|
55
|
+
super(BQIdentifierPreparer, self).__init__(
|
|
56
|
+
dialect,
|
|
57
|
+
initial_quote='[',
|
|
58
|
+
final_quote=']',
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def format_label(self, label, name=None):
|
|
62
|
+
""" bq can't handle quoting labels """
|
|
63
|
+
return name or label.name
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class BQDialect(MSDialect):
|
|
67
|
+
statement_compiler = BQSQLCompiler
|
|
68
|
+
preparer = BQIdentifierPreparer
|
|
69
|
+
colspecs = {
|
|
70
|
+
sqltypes.String: BQString
|
|
71
|
+
}
|
{sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 1.1
|
|
2
2
|
Name: sqlalchemy-bigquery
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: BigQuery for SQLAlchemy
|
|
5
5
|
Home-page: UNKNOWN
|
|
6
6
|
Author: Conrad Dean
|
|
@@ -26,51 +26,47 @@ Description: BigQuery dialect for SQLAlchemy.
|
|
|
26
26
|
in a regular service call.
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
To Install
|
|
29
|
+
To Install::
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
pip install sqlalchemy-bigquery
|
|
33
|
-
```
|
|
31
|
+
pip install sqlalchemy-bigquery
|
|
34
32
|
|
|
35
|
-
Usage Example
|
|
33
|
+
Usage Example::
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
FROM [fruit.table] GROUP BY fruit_type
|
|
73
|
-
```
|
|
35
|
+
>>> import sqlalchemy.sql as sql
|
|
36
|
+
>>>
|
|
37
|
+
>>> from sqlalchemy import func
|
|
38
|
+
>>> import sqlalchemy_bigquery.base as bq
|
|
39
|
+
>>>
|
|
40
|
+
>>>
|
|
41
|
+
>>> country = sql.column("country")
|
|
42
|
+
>>> fruit_type = sql.column("fruit_type")
|
|
43
|
+
>>> calories = sql.column("calories")
|
|
44
|
+
>>> total_usa = func.sum(
|
|
45
|
+
... sql.case(
|
|
46
|
+
... [(country == "usa", 1)],
|
|
47
|
+
... else_=0
|
|
48
|
+
... )
|
|
49
|
+
... ).label("Total_in_USA")
|
|
50
|
+
>>> total_japan = func.sum(
|
|
51
|
+
... sql.case(
|
|
52
|
+
... [(country == "japan", 1)],
|
|
53
|
+
... else_=0
|
|
54
|
+
... )
|
|
55
|
+
... ).label("Total_in_Japan")
|
|
56
|
+
>>> s = sql.select([
|
|
57
|
+
... fruit_type,
|
|
58
|
+
... total_usa,
|
|
59
|
+
... total_japan,
|
|
60
|
+
... ]).select_from(sql.table("fruit.table")
|
|
61
|
+
... ).group_by(
|
|
62
|
+
... fruit_type
|
|
63
|
+
... ).compile(
|
|
64
|
+
... compile_kwargs={"literal_binds": True},
|
|
65
|
+
... dialect=bq.BQDialect()
|
|
66
|
+
... )
|
|
67
|
+
>>> print str(s)
|
|
68
|
+
SELECT fruit_type, sum(CASE WHEN (country = 'usa') THEN 1 ELSE 0 END) AS Total_in_USA, sum(CASE WHEN (country = 'japan') THEN 1 ELSE 0 END) AS Total_in_Japan
|
|
69
|
+
FROM [fruit.table] GROUP BY fruit_type
|
|
74
70
|
|
|
75
71
|
Keywords: SQLAlchemy Google BigQuery
|
|
76
72
|
Platform: UNKNOWN
|
|
@@ -6,7 +6,7 @@ from sqlalchemy import func
|
|
|
6
6
|
import sqlalchemy_bigquery.base as bq
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
def
|
|
9
|
+
def test_mixed_case_function_label_not_quoted():
|
|
10
10
|
s = sql.select([
|
|
11
11
|
func.sum().label("Pork")
|
|
12
12
|
]).compile(
|
|
@@ -25,3 +25,26 @@ def test_table_is_quoted_with_square_brackets():
|
|
|
25
25
|
dialect=bq.BQDialect()
|
|
26
26
|
)
|
|
27
27
|
assert "[with.dot]" in str(s)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_mixed_case_column_not_quoted():
|
|
31
|
+
s = sql.select([
|
|
32
|
+
sql.column("Pork")
|
|
33
|
+
]).compile(
|
|
34
|
+
dialect=bq.BQDialect()
|
|
35
|
+
)
|
|
36
|
+
assert "[Pork]" not in str(s)
|
|
37
|
+
assert "Pork" in str(s)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_string_literals_correctly_quoted():
|
|
41
|
+
s = sql.select([
|
|
42
|
+
func.look_at(sql.column("something"), "here's a single-quote")
|
|
43
|
+
]).select_from(
|
|
44
|
+
sql.table("something_else")
|
|
45
|
+
).compile(
|
|
46
|
+
compile_kwargs={"literal_binds": True},
|
|
47
|
+
dialect=bq.BQDialect()
|
|
48
|
+
)
|
|
49
|
+
assert "here''s" not in str(s)
|
|
50
|
+
assert "here\'s" in str(s)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
include README.md
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
BigQuery dialect for SQLAlchemy.
|
|
2
|
-
|
|
3
|
-
BigQuery implements a DSL that is similar to SQL with a few quirks:
|
|
4
|
-
|
|
5
|
-
1. It has a "group each by" hint for grouping over large amounts of data
|
|
6
|
-
2. You need to use the "join each ... on" form when joining on a table larger than a small number of megabytes.
|
|
7
|
-
3. You can't quote columns, but you can quote tables. But probably not table aliasess.
|
|
8
|
-
4. Because you can't quote columns, you are limited to colums with no spaces, only alpha-numeric characters with underscores, and you can only start a column with a letter or underscore
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
The first two issues (the non-standard "each" modifier for grouping and joining) has not been addressed yet. BigQuery pushes the responsibility of when to recognize a table is too big for certain operations, and shifts burden onto you when you want to use those modifiers. Sometimes you need them, sometimes you don't. Leaving this as an exercise to the user to just string replace those out of what this dialect returns.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
### Usage
|
|
15
|
-
|
|
16
|
-
There currently isn't support for using sqlalchemy to connect to
|
|
17
|
-
BigQuery. Currently there's only support for generating SQL to send
|
|
18
|
-
in a regular service call.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
To Install
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
pip install sqlalchemy-bigquery
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
Usage Example
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
>>> import sqlalchemy.sql as sql
|
|
31
|
-
>>>
|
|
32
|
-
>>> from sqlalchemy import func
|
|
33
|
-
>>> import sqlalchemy_bigquery.base as bq
|
|
34
|
-
>>>
|
|
35
|
-
>>>
|
|
36
|
-
>>> country = sql.column("country")
|
|
37
|
-
>>> fruit_type = sql.column("fruit_type")
|
|
38
|
-
>>> calories = sql.column("calories")
|
|
39
|
-
>>> total_usa = func.sum(
|
|
40
|
-
... sql.case(
|
|
41
|
-
... [(country == "usa", 1)],
|
|
42
|
-
... else_=0
|
|
43
|
-
... )
|
|
44
|
-
... ).label("Total_in_USA")
|
|
45
|
-
>>> total_japan = func.sum(
|
|
46
|
-
... sql.case(
|
|
47
|
-
... [(country == "japan", 1)],
|
|
48
|
-
... else_=0
|
|
49
|
-
... )
|
|
50
|
-
... ).label("Total_in_Japan")
|
|
51
|
-
>>> s = sql.select([
|
|
52
|
-
... fruit_type,
|
|
53
|
-
... total_usa,
|
|
54
|
-
... total_japan,
|
|
55
|
-
... ]).select_from(sql.table("fruit.table")
|
|
56
|
-
... ).group_by(
|
|
57
|
-
... fruit_type
|
|
58
|
-
... ).compile(
|
|
59
|
-
... compile_kwargs={"literal_binds": True},
|
|
60
|
-
... dialect=bq.BQDialect()
|
|
61
|
-
... )
|
|
62
|
-
>>> print str(s)
|
|
63
|
-
SELECT fruit_type, sum(CASE WHEN (country = 'usa') THEN 1 ELSE 0 END) AS Total_in_USA, sum(CASE WHEN (country = 'japan') THEN 1 ELSE 0 END) AS Total_in_Japan
|
|
64
|
-
FROM [fruit.table] GROUP BY fruit_type
|
|
65
|
-
```
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import re
|
|
3
|
-
|
|
4
|
-
from setuptools import setup
|
|
5
|
-
|
|
6
|
-
v = open(os.path.join(os.path.dirname(__file__), 'sqlalchemy_bigquery', '__init__.py'))
|
|
7
|
-
VERSION = re.compile(r".*__version__ = '(.*?)'", re.S).match(v.read()).group(1)
|
|
8
|
-
v.close()
|
|
9
|
-
|
|
10
|
-
readme = os.path.join(os.path.dirname(__file__), 'README.md')
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
setup(name='sqlalchemy_bigquery',
|
|
14
|
-
version=VERSION,
|
|
15
|
-
description="BigQuery for SQLAlchemy",
|
|
16
|
-
long_description=open(readme).read(),
|
|
17
|
-
classifiers=[
|
|
18
|
-
'Development Status :: 3 - Alpha',
|
|
19
|
-
'Environment :: Console',
|
|
20
|
-
'Intended Audience :: Developers',
|
|
21
|
-
'Programming Language :: Python',
|
|
22
|
-
'Programming Language :: Python :: 3',
|
|
23
|
-
'Programming Language :: Python :: Implementation :: CPython',
|
|
24
|
-
'Topic :: Database :: Front-Ends',
|
|
25
|
-
],
|
|
26
|
-
keywords='SQLAlchemy Google BigQuery',
|
|
27
|
-
author='Conrad Dean',
|
|
28
|
-
author_email='conrad.p.dean@gmail.com',
|
|
29
|
-
license='MIT',
|
|
30
|
-
packages=['sqlalchemy_bigquery'],
|
|
31
|
-
include_package_data=True,
|
|
32
|
-
tests_require=['py.test'],
|
|
33
|
-
zip_safe=False,
|
|
34
|
-
entry_points={
|
|
35
|
-
'sqlalchemy.dialects': [
|
|
36
|
-
'bigquery = sqlalchemy_bigquery.pyodbc:BigQueryDialect_pyodbc',
|
|
37
|
-
'bigquery.pyodbc = sqlalchemy_bigquery.pyodbc:BigQueryDialect_pyodbc',
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
)
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Support for Google BigQuery.
|
|
3
|
-
|
|
4
|
-
Does not support actually connecting to BQ.
|
|
5
|
-
Directly derived from the mssql dialect with minor modifications
|
|
6
|
-
|
|
7
|
-
"""
|
|
8
|
-
import sqlalchemy.dialects.mssql.base as mssql_base
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
from sqlalchemy.dialects.mssql.base import MSDialect
|
|
12
|
-
from sqlalchemy.sql import compiler
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class BQSQLCompiler(mssql_base.MSSQLCompiler):
|
|
16
|
-
pass
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class BQIdentifierPreparer(compiler.IdentifierPreparer):
|
|
20
|
-
def __init__(self, dialect):
|
|
21
|
-
super(BQIdentifierPreparer, self).__init__(
|
|
22
|
-
dialect, initial_quote='[', final_quote=']'
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
def format_label(self, label, name=None):
|
|
26
|
-
""" bq can't handle quoting labels """
|
|
27
|
-
return name or label.name
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class BQDialect(MSDialect):
|
|
31
|
-
statement_compiler = BQSQLCompiler
|
|
32
|
-
preparer = BQIdentifierPreparer
|
|
File without changes
|
{sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery/requirements.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sqlalchemy_bigquery-0.0.1dev → sqlalchemy_bigquery-0.0.4}/sqlalchemy_bigquery.egg-info/not-zip-safe
RENAMED
|
File without changes
|
|
File without changes
|