diff --git a/chdb/__init__.py b/chdb/__init__.py index b0ce8fc62cb..c5e9109c2fb 100644 --- a/chdb/__init__.py +++ b/chdb/__init__.py @@ -9,7 +9,7 @@ class ChdbError(Exception): _arrow_format = set({"dataframe", "arrowtable"}) _process_result_format_funs = { "dataframe": lambda x: to_df(x), - "arrowtable": lambda x: to_arrowTable(x) + "arrowtable": lambda x: to_arrowTable(x), } # If any UDF is defined, the path of the UDF will be set to this variable @@ -18,7 +18,7 @@ class ChdbError(Exception): # UDF script path will be f"{g_udf_path}/{func_name}.py" g_udf_path = "" -chdb_version = ('0', '6', '0') +chdb_version = ("0", "6", "0") if sys.version_info[:2] >= (3, 7): # get the path of the current file current_path = os.path.dirname(os.path.abspath(__file__)) @@ -79,5 +79,15 @@ def query(sql, output_format="CSV", path="", udf_path=""): return result_func(res) -__all__ = ["ChdbError", "query", "chdb_version", - "engine_version", "to_df", "to_arrowTable"] +# alias for query +sql = query + +__all__ = [ + "ChdbError", + "query", + "sql", + "chdb_version", + "engine_version", + "to_df", + "to_arrowTable", +] diff --git a/chdb/dataframe/query.py b/chdb/dataframe/query.py index 5d4cdabb111..e3c4a5c4006 100644 --- a/chdb/dataframe/query.py +++ b/chdb/dataframe/query.py @@ -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()) diff --git a/chdb/session/state.py b/chdb/session/state.py index fa478221ebd..30a6ee202b1 100644 --- a/chdb/session/state.py +++ b/chdb/session/state.py @@ -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 diff --git a/tests/test_udf.py b/tests/test_udf.py index 3f5b7336fec..8778fdeb3aa 100644 --- a/tests/test_udf.py +++ b/tests/test_udf.py @@ -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() @@ -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') @@ -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__":