次の例は、パス(キー) IDと列属性をSQLクエリーで参照できるようにするために、両方の種類のデータについて名前を変更する河川流量の外部テーブルのビューです。
例では、サンプルの河川流量データ セットを使用します。独自のデータを使用するには、テーブル名、列名、および許可オブジェクトを置き換えます。サンプル データ セットの信頼証明および格納場所の値については、例の変数置換を参照してください。
- NOS関連コマンドを実行するには、必要な権限を持つユーザーとしてデータベースにログオンします。
- 存在しない場合は、riverflow_parquet_pathという名前の外部テーブルを作成するか、データベース管理者に作成を依頼します。外部テーブルからの外部Parquetデータのフィルタリングを参照してください。
- 外部テーブルのビューを作成します。
REPLACE VIEW riverflowview_parquet AS ( SELECT CAST($path.$siteno AS CHAR(10)) TheSite, CAST($path.$year AS CHAR(4)) TheYear, CAST($path.$month AS CHAR(2)) TheMonth, CAST(SUBSTR($path.$day, 1, 2) AS CHAR(2)) TheDay, Flow, GageHeight GageHeight1, Precipitation, GageHeight2 FROM riverflow_parquet_path WHERE TheSite = site_no);
- ビューを問合わせます。
SELECT TOP 2 * FROM riverflowview_parquet;
結果:
TheSite TheYear TheMonth TheDay Site_no Flow GageHeight1 Precipitation GageHeight2 -------- ------- -------- ------ -------- ------ ----------- ------------- ----------- 09396100 2018 07 15 9396100 153.00 1.96 0.00 1.96 09396100 2018 07 15 9396100 150.00 1.95 0.00 1.95
- ビューでフィルタ処理して、サイト番号が09396100のサイト数を検索します。
SELECT thesite,COUNT(*) FROM riverflowview_parquet WHERE thesite='09396100' GROUP BY 1;
結果:
TheSite Count(*) ---------- ----------- 09396100 2906
- クエリーでEXPLAINを実行して、フィルタ処理がどのように行なわれているかを確認します。
EXPLAIN SELECT thesite,COUNT(*) FROM riverflowview_parquet WHERE thesite='09396100' GROUP BY 1;
結果:
Explanation --------------------------------------------------------------------------- [...] 3) We do a single-AMP RETRIEVE step from NOS_USR.riverflow_parquet_path in view riverflowview_parquet metadata by way of an all-rows scan with a condition of ( "(TD_SYSFNLIB.NosExtractVarFromPath ( NOS_USR.riverflow_parquet_path in view riverflowview_parquet.Location, '/S3/td-usgs.s3.amazonaws.com/', 2 )(CHAR(10), CHARACTER SET UNICODE, NOT CASESPECIFIC))= '09396100 '") into Spool 3 (all_amps), which is built locally on that AMP. Then we do a SORT to order Spool 3 by the sort key as the field_id list( 3, 2). The size of Spool 3 is estimated with no confidence to be 17 rows (11,985 bytes). The estimated time for this step is 0.60 seconds. 4) We do an all-AMPs RETRIEVE step in TD_Map1 from Spool 3 (Last Use) by way of an all-rows scan into Spool 2 (all_amps), which is binpacked and redistributed by size to all AMPs in TD_Map1. The size of Spool 2 is estimated with no confidence to be 17 rows ( 12,121 bytes). The estimated time for this step is 0.16 seconds. 5) We do an all-AMPs SUM step in TD_MAP1 to aggregate from 3 column partitions of NOS_USR.riverflow_parquet_path in view riverflowview_parquet by way of external metadata in Spool 2 (Last Use) with a condition of ("(TD_SYSFNLIB.NosExtractVarFromPath ( NOS_USR.riverflow_parquet_path in view riverflowview_parquet.Location, '/S3/td-usgs.s3.amazonaws.com/', 2 )(CHAR(10), CHARACTER SET UNICODE, NOT CASESPECIFIC)(FLOAT, FORMAT '-9.99999999999999E-999'))= (NOS_USR.riverflow_parquet_path in view riverflowview_parquet.site_no)"), and the grouping identifier in field 1. Aggregate Intermediate Results are computed globally, then placed in Spool 5 in TD_Map1. The size of Spool 5 is estimated with no confidence to be 1,215 rows (1,703,430 bytes). The estimated time for this step is 0.77 seconds. [...]
(3)ではパス フィルタリングを行なっています。メタデータ スプールを構築するためのパス フィルタリング式として定数09396100を使用しています。メタデータ スプールは、クエリーが実際に処理するオブジェクトのリストを識別するスプール テーブルです。
(5)では従来の行フィルタリングを行なっています。場所の文字列から抽出されたサイト番号とParquetデータの値(オブジェクト ストア内の実際のデータ)を比較します。