Skip to content

Commit

Permalink
Alias sql method to query
Browse files Browse the repository at this point in the history
  • Loading branch information
auxten committed Jun 5, 2024
1 parent 19bf2f5 commit 49c362b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion chdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def query(sql, output_format="CSV", path="", udf_path=""):
raise ChdbError(res.error_message())
return result_func(res)

# alias for query
sql = query

__all__ = ["ChdbError", "query", "chdb_version",
__all__ = ["ChdbError", "query", "sql", "chdb_version",
"engine_version", "to_df", "to_arrowTable"]
3 changes: 3 additions & 0 deletions chdb/dataframe/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def query(self, sql: str, **kwargs) -> "Table":
else:
raise ValueError("Table object is not initialized correctly")

# alias sql = query
sql = query

def show(self):
print(self.to_pandas())

Expand Down
3 changes: 3 additions & 0 deletions chdb/session/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ def query(self, sql, fmt="CSV"):
Execute a query.
"""
return query(sql, fmt, path=self._path)

# alias sql = query
sql = query
8 changes: 5 additions & 3 deletions tests/test_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from chdb.udf import chdb_udf
from chdb.session import Session
from chdb import query
from chdb import query, sql


@chdb_udf()
Expand All @@ -30,7 +30,8 @@ def test_define_in_function(self):
def sum_udf2(lhs, rhs):
return int(lhs) + int(rhs)

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


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

with Session() as session:
ret = session.query("select sum_udf2(11, 22)", "Debug")
# sql is a alias for query
ret = session.sql("select sum_udf2(11, 22)", "Debug")
self.assertEqual(str(ret), '"33"\n')

if __name__ == "__main__":
Expand Down

0 comments on commit 49c362b

Please sign in to comment.