CData Python Connector for Apache Impala

Build 21.0.7930

Querying Data

After connecting with the steps in Connecting, and reflecting some of the metadata with one of the methods in Reflecting Metadata, you can query data using a session object.

Querying Data Using the Query Method

If the mapping class has been prepared, it is used alongside a session object to query the data source. After binding the engine to the session, simply provide the mapping class to the session's query method, as below:

engine = create_engine("apacheimpala:///?Server=;Port=21050;")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query([CData].[Default].Customers).filter_by(Country="US"):
	print("_id: ", instance._id)
	print("City: ", instance.City)
	print("CompanyName: ", instance.CompanyName)

Querying Data Using the Execute Method

As an alternative, the session object can also run the query with the execute() method alongside the appropriate Table object. Assuming you have an active session, the below is just as viable:

[CData].[Default].Customers_table = [CData].[Default].Customers.metadata.tables["[CData].[Default].Customers"]
for instance in session.execute([CData].[Default][CData].[Default].Customers_table.c.Country == "US")):
	print("Id: ", instance.Id)
	print("FullName: ", instance.Name)
	print("City: ", instance.BillingCity)

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930