sql-blocks 1.25.517999999999__tar.gz → 1.25.518999999999__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.517999999999
3
+ Version: 1.25.518999999999
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sql_blocks"
3
- version = "1.25.517999999999"
3
+ version = "1.25.518999999999"
4
4
  authors = [
5
5
  { name="Julio Cascalles", email="julio.cascalles@outlook.com" },
6
6
  ]
@@ -3,7 +3,7 @@ from setuptools import setup
3
3
 
4
4
  setup(
5
5
  name = 'sql_blocks',
6
- version = '1.25.517999999999',
6
+ version = '1.25.518999999999',
7
7
  author = 'Júlio Cascalles',
8
8
  author_email = 'julio.cascalles@outlook.com',
9
9
  packages = ['sql_blocks'],
@@ -880,7 +880,7 @@ class QueryLanguage:
880
880
  return self.join_with_tabs(values, ' AND ')
881
881
 
882
882
  def sort_by(self, values: list) -> str:
883
- if OrderBy.sort == SortType.DESC:
883
+ if OrderBy.sort == SortType.DESC and OrderBy.ascending(values[-1]):
884
884
  values[-1] += ' DESC'
885
885
  return self.join_with_tabs(values, ',')
886
886
 
@@ -1138,9 +1138,16 @@ class DatabricksLanguage(DataAnalysisLanguage):
1138
1138
  )
1139
1139
 
1140
1140
 
1141
+ class FileExtension(Enum):
1142
+ CSV = 'read_csv'
1143
+ XLSX = 'read_excel'
1144
+ JSON = 'read_json'
1145
+ HTML = 'read_html'
1146
+
1141
1147
  class PandasLanguage(DataAnalysisLanguage):
1142
1148
  pattern = '{_from}{where}{select}{group_by}{order_by}'
1143
1149
  has_default = {key: False for key in KEYWORD}
1150
+ file_extension = FileExtension.CSV
1144
1151
 
1145
1152
  def add_field(self, values: list) -> str:
1146
1153
  def line_field_fmt(field: str) -> str:
@@ -1160,7 +1167,9 @@ class PandasLanguage(DataAnalysisLanguage):
1160
1167
  for table in values:
1161
1168
  table, *join = [t.strip() for t in re.split('JOIN|LEFT|RIGHT|ON', table) if t.strip()]
1162
1169
  alias, table = SQLObject.split_alias(table)
1163
- result += f"\ndf_{table} = pd.read_csv('{table}.csv')"
1170
+ result += "\ndf_{table} = pd.{func}('{table}.{ext}')".format(
1171
+ table=table, func=self.file_extension.value, ext=self.file_extension.name.lower()
1172
+ )
1164
1173
  names[alias] = table
1165
1174
  if join:
1166
1175
  a1, f1, a2, f2 = [r.strip() for r in re.split('[().=]', join[-1]) if r]
@@ -1188,7 +1197,7 @@ class PandasLanguage(DataAnalysisLanguage):
1188
1197
  level += 2
1189
1198
  if '%' in const[2]:
1190
1199
  level += 1
1191
- const = f"'{const[1]}'"
1200
+ const = f"'{const[1]}')"
1192
1201
  op = STR_FUNC[level]
1193
1202
  else:
1194
1203
  const = ''.join(const)
@@ -2035,24 +2044,19 @@ def detect(text: str, join_queries: bool = True, format: str='') -> Select | lis
2035
2044
 
2036
2045
 
2037
2046
  if __name__ == "__main__":
2038
- query = detect('''
2047
+ query = detect("""
2039
2048
  SELECT
2040
2049
  e.gender, d.region,
2041
2050
  Avg(e.age)
2042
2051
  FROM
2043
2052
  Employees e
2044
- LEFT JOIN Department d ON (e.depto_id = d.id)
2053
+ JOIN Departments d ON (e.depto_id = d.id)
2045
2054
  WHERE
2046
- e.name LIKE 'C%'
2055
+ e.name LIKE 'A%'
2047
2056
  GROUP BY
2048
2057
  e.gender, d.region
2049
2058
  ORDER BY
2050
2059
  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)
2060
+ """)
2061
+ PandasLanguage.file_extension = FileExtension.XLSX
2062
+ print( query.translate_to(PandasLanguage) )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sql_blocks
3
- Version: 1.25.517999999999
3
+ Version: 1.25.518999999999
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