Skip to content

Commit 66ac8e9

Browse files
authored
Alias sql method to query (#219)
* Alias sql method to query * Fix py code style
1 parent c84060d commit 66ac8e9

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

chdb/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ChdbError(Exception):
99
_arrow_format = set({"dataframe", "arrowtable"})
1010
_process_result_format_funs = {
1111
"dataframe": lambda x: to_df(x),
12-
"arrowtable": lambda x: to_arrowTable(x)
12+
"arrowtable": lambda x: to_arrowTable(x),
1313
}
1414

1515
# If any UDF is defined, the path of the UDF will be set to this variable
@@ -18,7 +18,7 @@ class ChdbError(Exception):
1818
# UDF script path will be f"{g_udf_path}/{func_name}.py"
1919
g_udf_path = ""
2020

21-
chdb_version = ('0', '6', '0')
21+
chdb_version = ("0", "6", "0")
2222
if sys.version_info[:2] >= (3, 7):
2323
# get the path of the current file
2424
current_path = os.path.dirname(os.path.abspath(__file__))
@@ -79,5 +79,15 @@ def query(sql, output_format="CSV", path="", udf_path=""):
7979
return result_func(res)
8080

8181

82-
__all__ = ["ChdbError", "query", "chdb_version",
83-
"engine_version", "to_df", "to_arrowTable"]
82+
# alias for query
83+
sql = query
84+
85+
__all__ = [
86+
"ChdbError",
87+
"query",
88+
"sql",
89+
"chdb_version",
90+
"engine_version",
91+
"to_df",
92+
"to_arrowTable",
93+
]

chdb/dataframe/query.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def query(self, sql: str, **kwargs) -> "Table":
134134
else:
135135
raise ValueError("Table object is not initialized correctly")
136136

137+
# alias sql = query
138+
sql = query
139+
137140
def show(self):
138141
print(self.to_pandas())
139142

chdb/session/state.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ def query(self, sql, fmt="CSV"):
4545
Execute a query.
4646
"""
4747
return query(sql, fmt, path=self._path)
48+
49+
# alias sql = query
50+
sql = query

tests/test_udf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44
from chdb.udf import chdb_udf
55
from chdb.session import Session
6-
from chdb import query
6+
from chdb import query, sql
77

88

99
@chdb_udf()
@@ -30,7 +30,8 @@ def test_define_in_function(self):
3030
def sum_udf2(lhs, rhs):
3131
return int(lhs) + int(rhs)
3232

33-
ret = query("select sum_udf2(11, 22)", "Debug")
33+
# sql is a alias for query
34+
ret = sql("select sum_udf2(11, 22)", "Debug")
3435
self.assertEqual(str(ret), '"33"\n')
3536

3637

@@ -51,7 +52,8 @@ def sum_udf2(lhs, rhs):
5152
return int(lhs) + int(rhs)
5253

5354
with Session() as session:
54-
ret = session.query("select sum_udf2(11, 22)", "Debug")
55+
# sql is a alias for query
56+
ret = session.sql("select sum_udf2(11, 22)", "Debug")
5557
self.assertEqual(str(ret), '"33"\n')
5658

5759
if __name__ == "__main__":

0 commit comments

Comments
 (0)