You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2023/04/11 11:25:09 UTC

[GitHub] [arrow-adbc] lidavidm commented on a diff in pull request #569: test(python/adbc_driver_postgres): add benchmark suite via asv

lidavidm commented on code in PR #569:
URL: https://github.com/apache/arrow-adbc/pull/569#discussion_r1162671475


##########
python/adbc_driver_postgresql/benchmarks/benchmarks.py:
##########
@@ -0,0 +1,175 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import abc
+import asyncio
+import itertools
+import os
+
+import asyncpg
+import duckdb
+import pandas
+import psycopg
+import sqlalchemy
+
+import adbc_driver_postgresql.dbapi
+
+
+class BenchmarkBase(abc.ABC):
+    async_conn: asyncpg.Connection
+    async_runner: asyncio.Runner
+    conn: adbc_driver_postgresql.dbapi.Connection
+    duck: duckdb.DuckDBPyConnection
+    sqlalchemy_connection: sqlalchemy.engine.base.Connection
+
+    def setup(self, *args, **kwargs) -> None:
+        self.uri = os.environ["ADBC_POSTGRESQL_TEST_URI"]
+
+        self.table = self._make_table_name(*args, **kwargs)
+
+        self.async_runner = asyncio.Runner()
+        self.async_conn = self.async_runner.run(asyncpg.connect(dsn=self.uri))
+
+        self.conn = adbc_driver_postgresql.dbapi.connect(self.uri)
+
+        self.duck = duckdb.connect()
+        self.duck.sql("INSTALL postgres_scanner")
+        self.duck.sql("LOAD postgres_scanner")
+        self.duck.sql(f"CALL postgres_attach('{self.uri}')")
+
+        uri = self.uri.replace("postgres://", "postgresql+psycopg2://")
+        self.sqlalchemy_connection = sqlalchemy.create_engine(uri).connect()
+
+    def teardown(self, *args, **kwargs) -> None:
+        self.async_runner.close()
+        self.conn.close()
+        self.sqlalchemy_connection.close()
+
+    @abc.abstractmethod
+    def _make_table_name(self, *args, **kwargs) -> str:
+        ...
+
+    def time_pandas_adbc(self, row_count: int, data_type: str) -> None:
+        with self.conn.cursor() as cursor:
+            cursor.execute(f"SELECT * FROM {self.table}")
+            cursor.fetch_df()
+
+    def time_pandas_asyncpg(self, row_count: int, data_type: str) -> None:
+        records = self.async_runner.run(
+            self.async_conn.fetch(f"SELECT * FROM {self.table}")
+        )
+        pandas.DataFrame(records)
+
+    # TODO: fails with 'undefined symbol' (probably need to get it into Conda)
+    # def time_pandas_pgeon(self, row_count: int) -> None:

Review Comment:
   Probably yes, hence we need to get it into conda.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org