Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: integration for pg_handler added #937

Merged
merged 6 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions evadb/third_party/databases/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,52 @@
# 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.
from evadb.third_party.databases.postgres.postgres_handler import PostgresHandler
import os
import pip
import importlib

INSTALL_CACHE = []


def get_database_handler(engine: str, **kwargs):
"""
Return the database handler. User should modify this function for
their new integrated handlers.
"""

# Dynamically install dependencies.
dynamic_install(engine)

# Dynamically import the top module.
mod = dynamic_import(engine)

if engine == "postgres":
return PostgresHandler(engine, **kwargs)
return mod.PostgresHandler(engine, **kwargs)
else:
raise NotImplementedError(f"Engine {engine} is not supported")
raise NotImplementedError(f"Engine {engine} is not supported")


def dynamic_install(handler_dir):
"""
Dynamically install package from requirements.txt.
"""

# Skip installation
if handler_dir in INSTALL_CACHE:
return

INSTALL_CACHE.append(handler_dir)

req_file = os.path.join(handler_dir, "requirements.txt")
if os.path.isfile(req_file):
with open(req_file) as f:
for package in f.read().splitlines():
if hasattr(pip, "main"):
pip.main(["install", package])
else:
pip._internal.main(["install", package])


def dynamic_import(handler_dir):
import_path = f"evadb.third_party.databases.{handler_dir}.{handler_dir}_handler"
return importlib.import_module(import_path)
2 changes: 2 additions & 0 deletions evadb/third_party/databases/postgres/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
psycopg<=2.9.7
pandas<=2.0.2
Copy link
Collaborator

@xzdandy xzdandy Aug 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we want to have a cap on the version? This very likely leads to version conflicts, given postgres is not installed with the evadb. From my experience with the current setup.py, pip install -e .[dev,some_other_dependency] works, but pip install -e .[dev] and then pip install -e .[some_other_dependency] will print out version conflict warnings/errors, especially when we have version caps on some packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Removed it.