sql-blocks 1.25.517999999999__py3-none-any.whl → 1.25.528999999999__py3-none-any.whl
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.
- sql_blocks/sql_blocks.py +18 -27
- {sql_blocks-1.25.517999999999.dist-info → sql_blocks-1.25.528999999999.dist-info}/METADATA +1 -1
- sql_blocks-1.25.528999999999.dist-info/RECORD +7 -0
- sql_blocks-1.25.517999999999.dist-info/RECORD +0 -7
- {sql_blocks-1.25.517999999999.dist-info → sql_blocks-1.25.528999999999.dist-info}/LICENSE +0 -0
- {sql_blocks-1.25.517999999999.dist-info → sql_blocks-1.25.528999999999.dist-info}/WHEEL +0 -0
- {sql_blocks-1.25.517999999999.dist-info → sql_blocks-1.25.528999999999.dist-info}/top_level.txt +0 -0
sql_blocks/sql_blocks.py
CHANGED
@@ -131,6 +131,7 @@ class SQLObject:
|
|
131
131
|
return s1 - s2
|
132
132
|
|
133
133
|
def delete(self, search: str, keys: list=USUAL_KEYS, exact: bool=False):
|
134
|
+
search = re.escape(search)
|
134
135
|
if exact:
|
135
136
|
not_match = lambda item: not re.search(fr'\w*[.]*{search}$', item)
|
136
137
|
else:
|
@@ -880,7 +881,7 @@ class QueryLanguage:
|
|
880
881
|
return self.join_with_tabs(values, ' AND ')
|
881
882
|
|
882
883
|
def sort_by(self, values: list) -> str:
|
883
|
-
if OrderBy.sort == SortType.DESC:
|
884
|
+
if OrderBy.sort == SortType.DESC and OrderBy.ascending(values[-1]):
|
884
885
|
values[-1] += ' DESC'
|
885
886
|
return self.join_with_tabs(values, ',')
|
886
887
|
|
@@ -1138,9 +1139,16 @@ class DatabricksLanguage(DataAnalysisLanguage):
|
|
1138
1139
|
)
|
1139
1140
|
|
1140
1141
|
|
1142
|
+
class FileExtension(Enum):
|
1143
|
+
CSV = 'read_csv'
|
1144
|
+
XLSX = 'read_excel'
|
1145
|
+
JSON = 'read_json'
|
1146
|
+
HTML = 'read_html'
|
1147
|
+
|
1141
1148
|
class PandasLanguage(DataAnalysisLanguage):
|
1142
1149
|
pattern = '{_from}{where}{select}{group_by}{order_by}'
|
1143
1150
|
has_default = {key: False for key in KEYWORD}
|
1151
|
+
file_extension = FileExtension.CSV
|
1144
1152
|
|
1145
1153
|
def add_field(self, values: list) -> str:
|
1146
1154
|
def line_field_fmt(field: str) -> str:
|
@@ -1160,7 +1168,9 @@ class PandasLanguage(DataAnalysisLanguage):
|
|
1160
1168
|
for table in values:
|
1161
1169
|
table, *join = [t.strip() for t in re.split('JOIN|LEFT|RIGHT|ON', table) if t.strip()]
|
1162
1170
|
alias, table = SQLObject.split_alias(table)
|
1163
|
-
result +=
|
1171
|
+
result += "\ndf_{table} = pd.{func}('{table}.{ext}')".format(
|
1172
|
+
table=table, func=self.file_extension.value, ext=self.file_extension.name.lower()
|
1173
|
+
)
|
1164
1174
|
names[alias] = table
|
1165
1175
|
if join:
|
1166
1176
|
a1, f1, a2, f2 = [r.strip() for r in re.split('[().=]', join[-1]) if r]
|
@@ -1188,7 +1198,7 @@ class PandasLanguage(DataAnalysisLanguage):
|
|
1188
1198
|
level += 2
|
1189
1199
|
if '%' in const[2]:
|
1190
1200
|
level += 1
|
1191
|
-
const = f"'{const[1]}'"
|
1201
|
+
const = f"'{const[1]}')"
|
1192
1202
|
op = STR_FUNC[level]
|
1193
1203
|
else:
|
1194
1204
|
const = ''.join(const)
|
@@ -1428,7 +1438,11 @@ class CypherParser(Parser):
|
|
1428
1438
|
raise ValueError(f'Unknown function `{func_name}`.')
|
1429
1439
|
if ':' in token:
|
1430
1440
|
token, field_alias = token.split(':')
|
1431
|
-
|
1441
|
+
if extra_classes == [OrderBy]:
|
1442
|
+
class_type = class_type().As(field_alias, OrderBy)
|
1443
|
+
extra_classes = []
|
1444
|
+
else:
|
1445
|
+
class_type = class_type().As(field_alias)
|
1432
1446
|
class_list = [class_type]
|
1433
1447
|
class_list += extra_classes
|
1434
1448
|
FieldList(token, class_list).add('', self.queries[-1])
|
@@ -2033,26 +2047,3 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
|
|
2033
2047
|
return result
|
2034
2048
|
# ===========================================================================================//
|
2035
2049
|
|
2036
|
-
|
2037
|
-
if __name__ == "__main__":
|
2038
|
-
query = detect('''
|
2039
|
-
SELECT
|
2040
|
-
e.gender, d.region,
|
2041
|
-
Avg(e.age)
|
2042
|
-
FROM
|
2043
|
-
Employees e
|
2044
|
-
LEFT JOIN Department d ON (e.depto_id = d.id)
|
2045
|
-
WHERE
|
2046
|
-
e.name LIKE 'C%'
|
2047
|
-
GROUP BY
|
2048
|
-
e.gender, d.region
|
2049
|
-
ORDER BY
|
2050
|
-
d.region DESC
|
2051
|
-
''')
|
2052
|
-
print('='*50)
|
2053
|
-
print(query)
|
2054
|
-
print('-'*50)
|
2055
|
-
# Select.DefaultLanguage = DatabricksLanguage
|
2056
|
-
Select.DefaultLanguage = PandasLanguage
|
2057
|
-
print(query)
|
2058
|
-
print('='*50)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sql_blocks
|
3
|
-
Version: 1.25.
|
3
|
+
Version: 1.25.528999999999
|
4
4
|
Summary: Allows you to create objects for parts of SQL query commands. Also to combine these objects by joining them, adding or removing parts...
|
5
5
|
Home-page: https://github.com/julio-cascalles/sql_blocks
|
6
6
|
Author: Júlio Cascalles
|
@@ -0,0 +1,7 @@
|
|
1
|
+
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
+
sql_blocks/sql_blocks.py,sha256=qhzO4tlxBE3dSqDZ-ow1b08H90xDytWXrFMrf6Y-5Og,69096
|
3
|
+
sql_blocks-1.25.528999999999.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
+
sql_blocks-1.25.528999999999.dist-info/METADATA,sha256=GNAFIVbNrBrijE1PbjoHaaPRIwrC_NbSLEd-VF0WWyc,22235
|
5
|
+
sql_blocks-1.25.528999999999.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
sql_blocks-1.25.528999999999.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
+
sql_blocks-1.25.528999999999.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
sql_blocks/__init__.py,sha256=5ItzGCyqqa6kwY8wvF9kapyHsAiWJ7KEXCcC-OtdXKg,37
|
2
|
-
sql_blocks/sql_blocks.py,sha256=hk1wSGny-vY7k4nO94zLsCmM1C2Curi5Cv7hVqa1mUw,69100
|
3
|
-
sql_blocks-1.25.517999999999.dist-info/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
|
4
|
-
sql_blocks-1.25.517999999999.dist-info/METADATA,sha256=w2m3bbhDdnCeTqnrzeloyAmBuXX5nkwWqwlPBoPh0ac,22235
|
5
|
-
sql_blocks-1.25.517999999999.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
sql_blocks-1.25.517999999999.dist-info/top_level.txt,sha256=57AbUvUjYNy4m1EqDaU3WHeP-uyIAfV0n8GAUp1a1YQ,11
|
7
|
-
sql_blocks-1.25.517999999999.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{sql_blocks-1.25.517999999999.dist-info → sql_blocks-1.25.528999999999.dist-info}/top_level.txt
RENAMED
File without changes
|