CData Python Connector for Microsoft SQL Server Analysis Services

Build 23.0.8839

データのクエリ

接続 の手順を使用して接続し、メタデータの反映 メソッドのいずれかを使用してメタデータの一部を反映させたら、セッションオブジェクトを使用してデータをクエリできます。

query メソッドを使用したデータのクエリ

マッピングクラスが用意されている場合は、セッションオブジェクトと併用してデータソースをクエリします。エンジンをセッションにバインドしたら、マッピングクラスをセッションのクエリメソッドに提供します。

次に例を示します。

engine = create_engine("ssas:///?User=myuseraccount;Password=mypassword;URL=http://localhost/OLAP/msmdpump.dll;")
factory = sessionmaker(bind=engine)
session = factory()
for instance in session.query([AdventureWorksDW2012Multidimensional-SE].[Adventure Works].Customer).filter_by(Country="Australia"):
	print("Id: ", instance.Id)
	print("Country: ", instance.Country)
	print("Education: ", instance.Education)
	print("---------")

execute メソッドを使用したデータのクエリ

セッションオブジェクトは、適切なテーブルオブジェクトと一緒にexecute() メソッドを使用してクエリを実行することもできます。アクティブなセッションがあると仮定すると、以下は同様に実行可能です。
[AdventureWorksDW2012Multidimensional-SE].[Adventure Works].Customer_table = [AdventureWorksDW2012Multidimensional-SE].[Adventure Works].Customer.metadata.tables["[AdventureWorksDW2012Multidimensional-SE].[Adventure Works].Customer"]
for instance in session.execute([AdventureWorksDW2012Multidimensional-SE].[Adventure Works].Customer_table.select().where([AdventureWorksDW2012Multidimensional-SE].[Adventure Works].Customer_table.c.Country == "Australia")):
	print("Id: ", instance.Id)
	print("FullName: ", instance.Name)
	print("City: ", instance.BillingCity)
	print("---------")

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839