sqlalchemy-bigquery 0.0.1dev__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.
@@ -0,0 +1 @@
1
+ include README.md
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 1.1
2
+ Name: sqlalchemy_bigquery
3
+ Version: 0.0.1dev
4
+ Summary: BigQuery for SQLAlchemy
5
+ Home-page: UNKNOWN
6
+ Author: Conrad Dean
7
+ Author-email: conrad.p.dean@gmail.com
8
+ License: MIT
9
+ Description: BigQuery dialect for SQLAlchemy.
10
+
11
+ BigQuery implements a DSL that is similar to SQL with a few quirks:
12
+
13
+ 1. It has a "group each by" hint for grouping over large amounts of data
14
+ 2. You need to use the "join each ... on" form when joining on a table larger than a small number of megabytes.
15
+ 3. You can't quote columns, but you can quote tables. But probably not table aliasess.
16
+ 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
17
+
18
+
19
+ 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.
20
+
21
+
22
+ ### Usage
23
+
24
+ There currently isn't support for using sqlalchemy to connect to
25
+ BigQuery. Currently there's only support for generating SQL to send
26
+ in a regular service call.
27
+
28
+
29
+ To Install
30
+
31
+ ```
32
+ pip install sqlalchemy-bigquery
33
+ ```
34
+
35
+ Usage Example
36
+
37
+ ```
38
+ >>> import sqlalchemy.sql as sql
39
+ >>>
40
+ >>> from sqlalchemy import func
41
+ >>> import sqlalchemy_bigquery.base as bq
42
+ >>>
43
+ >>>
44
+ >>> country = sql.column("country")
45
+ >>> fruit_type = sql.column("fruit_type")
46
+ >>> calories = sql.column("calories")
47
+ >>> total_usa = func.sum(
48
+ ... sql.case(
49
+ ... [(country == "usa", 1)],
50
+ ... else_=0
51
+ ... )
52
+ ... ).label("Total_in_USA")
53
+ >>> total_japan = func.sum(
54
+ ... sql.case(
55
+ ... [(country == "japan", 1)],
56
+ ... else_=0
57
+ ... )
58
+ ... ).label("Total_in_Japan")
59
+ >>> s = sql.select([
60
+ ... fruit_type,
61
+ ... total_usa,
62
+ ... total_japan,
63
+ ... ]).select_from(sql.table("fruit.table")
64
+ ... ).group_by(
65
+ ... fruit_type
66
+ ... ).compile(
67
+ ... compile_kwargs={"literal_binds": True},
68
+ ... dialect=bq.BQDialect()
69
+ ... )
70
+ >>> print str(s)
71
+ 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
72
+ FROM [fruit.table] GROUP BY fruit_type
73
+ ```
74
+
75
+ Keywords: SQLAlchemy Google BigQuery
76
+ Platform: UNKNOWN
77
+ Classifier: Development Status :: 3 - Alpha
78
+ Classifier: Environment :: Console
79
+ Classifier: Intended Audience :: Developers
80
+ Classifier: Programming Language :: Python
81
+ Classifier: Programming Language :: Python :: 3
82
+ Classifier: Programming Language :: Python :: Implementation :: CPython
83
+ Classifier: Topic :: Database :: Front-Ends
@@ -0,0 +1,65 @@
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
+ ```
@@ -0,0 +1,9 @@
1
+ [egg_info]
2
+ tag_build = dev
3
+ tag_date = 0
4
+ tag_svn_revision = 0
5
+
6
+ [pytest]
7
+ addopts = --tb native -v -r fxX
8
+ python_files = test/*test_*.py
9
+
@@ -0,0 +1,40 @@
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
+ )
@@ -0,0 +1,6 @@
1
+ __version__ = '0.0.1'
2
+
3
+ from sqlalchemy.dialects import registry
4
+
5
+ registry.register("bigquery", "sqlalchemy_bigquery.pyodbc", "BigQueryDialect_pyodbc")
6
+ registry.register("bigquery.pyodbc", "sqlalchemy_bigquery.pyodbc", "BigQueryDialect_pyodbc")
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,5 @@
1
+ from sqlalchemy.dialects.mssql.pyodbc import MSDialect_pyodbc
2
+
3
+
4
+ class BigQueryDialect_pyodbc(MSDialect_pyodbc):
5
+ pass
@@ -0,0 +1,4 @@
1
+ from sqlalchemy.testing.requirements import SuiteRequirements
2
+
3
+ class Requirements(SuiteRequirements):
4
+ pass
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 1.1
2
+ Name: sqlalchemy-bigquery
3
+ Version: 0.0.1dev
4
+ Summary: BigQuery for SQLAlchemy
5
+ Home-page: UNKNOWN
6
+ Author: Conrad Dean
7
+ Author-email: conrad.p.dean@gmail.com
8
+ License: MIT
9
+ Description: BigQuery dialect for SQLAlchemy.
10
+
11
+ BigQuery implements a DSL that is similar to SQL with a few quirks:
12
+
13
+ 1. It has a "group each by" hint for grouping over large amounts of data
14
+ 2. You need to use the "join each ... on" form when joining on a table larger than a small number of megabytes.
15
+ 3. You can't quote columns, but you can quote tables. But probably not table aliasess.
16
+ 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
17
+
18
+
19
+ 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.
20
+
21
+
22
+ ### Usage
23
+
24
+ There currently isn't support for using sqlalchemy to connect to
25
+ BigQuery. Currently there's only support for generating SQL to send
26
+ in a regular service call.
27
+
28
+
29
+ To Install
30
+
31
+ ```
32
+ pip install sqlalchemy-bigquery
33
+ ```
34
+
35
+ Usage Example
36
+
37
+ ```
38
+ >>> import sqlalchemy.sql as sql
39
+ >>>
40
+ >>> from sqlalchemy import func
41
+ >>> import sqlalchemy_bigquery.base as bq
42
+ >>>
43
+ >>>
44
+ >>> country = sql.column("country")
45
+ >>> fruit_type = sql.column("fruit_type")
46
+ >>> calories = sql.column("calories")
47
+ >>> total_usa = func.sum(
48
+ ... sql.case(
49
+ ... [(country == "usa", 1)],
50
+ ... else_=0
51
+ ... )
52
+ ... ).label("Total_in_USA")
53
+ >>> total_japan = func.sum(
54
+ ... sql.case(
55
+ ... [(country == "japan", 1)],
56
+ ... else_=0
57
+ ... )
58
+ ... ).label("Total_in_Japan")
59
+ >>> s = sql.select([
60
+ ... fruit_type,
61
+ ... total_usa,
62
+ ... total_japan,
63
+ ... ]).select_from(sql.table("fruit.table")
64
+ ... ).group_by(
65
+ ... fruit_type
66
+ ... ).compile(
67
+ ... compile_kwargs={"literal_binds": True},
68
+ ... dialect=bq.BQDialect()
69
+ ... )
70
+ >>> print str(s)
71
+ 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
72
+ FROM [fruit.table] GROUP BY fruit_type
73
+ ```
74
+
75
+ Keywords: SQLAlchemy Google BigQuery
76
+ Platform: UNKNOWN
77
+ Classifier: Development Status :: 3 - Alpha
78
+ Classifier: Environment :: Console
79
+ Classifier: Intended Audience :: Developers
80
+ Classifier: Programming Language :: Python
81
+ Classifier: Programming Language :: Python :: 3
82
+ Classifier: Programming Language :: Python :: Implementation :: CPython
83
+ Classifier: Topic :: Database :: Front-Ends
@@ -0,0 +1,15 @@
1
+ MANIFEST.in
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ sqlalchemy_bigquery/__init__.py
6
+ sqlalchemy_bigquery/base.py
7
+ sqlalchemy_bigquery/pyodbc.py
8
+ sqlalchemy_bigquery/requirements.py
9
+ sqlalchemy_bigquery.egg-info/PKG-INFO
10
+ sqlalchemy_bigquery.egg-info/SOURCES.txt
11
+ sqlalchemy_bigquery.egg-info/dependency_links.txt
12
+ sqlalchemy_bigquery.egg-info/entry_points.txt
13
+ sqlalchemy_bigquery.egg-info/not-zip-safe
14
+ sqlalchemy_bigquery.egg-info/top_level.txt
15
+ test/test_suite.py
@@ -0,0 +1,4 @@
1
+ [sqlalchemy.dialects]
2
+ bigquery = sqlalchemy_bigquery.pyodbc:BigQueryDialect_pyodbc
3
+ bigquery.pyodbc = sqlalchemy_bigquery.pyodbc:BigQueryDialect_pyodbc
4
+
@@ -0,0 +1 @@
1
+ sqlalchemy_bigquery
@@ -0,0 +1,27 @@
1
+ # from sqlalchemy.testing.suite import *
2
+
3
+ import sqlalchemy.sql as sql
4
+ from sqlalchemy import func
5
+
6
+ import sqlalchemy_bigquery.base as bq
7
+
8
+
9
+ def test_mixed_case_column_not_quoted():
10
+ s = sql.select([
11
+ func.sum().label("Pork")
12
+ ]).compile(
13
+ dialect=bq.BQDialect()
14
+ )
15
+ assert "[Pork]" not in str(s)
16
+ assert "Pork" in str(s)
17
+
18
+
19
+ def test_table_is_quoted_with_square_brackets():
20
+ s = sql.select([
21
+ func.sum().label("Pork")
22
+ ]).select_from(
23
+ sql.table("with.dot")
24
+ ).compile(
25
+ dialect=bq.BQDialect()
26
+ )
27
+ assert "[with.dot]" in str(s)