概要
カスタムJDBCアダプタなどのアダプタによってはDISTINCT句をデータソース側にプッシュダウンできない場合があります。
本手順では、DISTINCT句をプッシュダウン可能にする手順を説明します。
本手順では、SQL Server 2019のJDBCドライバで作成したカスタムアダプタで操作を行いますが、他のアダプタでも適用可能です。
検証環境
製品 | バージョン | 備考 |
---|---|---|
TDV Server |
8.5.4 |
Windows Server 2019環境で実行 |
TDV Studo |
手順
1. アダプタの設定ファイルが存在する以下のパスに移動します。
[TDV Serverインストールフォルダ]\conf\adapters\system\[アダプタ名]
カスタムJDBCアダプタの場合は以下のパスに移動します。
[TDV Serverインストールフォルダ]\conf\adapters\custom\[アダプタ名]
2. <adapter name>_values.xml
というファイル名形式のファイルをテキストエディタなどで開きます。
3. ファイル内をdistinct
で検索し、/runtime/query/distinct
のname属性を持つ attribute を検索します(コメントアウトされています)。
4. 該当の attribute 全体をコピーし、ファイル先頭から4行目あたり、Please insert customized elements after this line.
のコメント下にペーストします。
5. value属性を、true
にします。
本手順の場合は以下の通りとなります。
<!-- Please insert customized elements after this line. -->
<ns15:attribute xmlns:ns15="http://www.compositesw.com/services/system/util/common">
<ns15:name>/runtime/query/distinct</ns15:name>
<ns15:type>BOOLEAN</ns15:type>
<ns15:value>true</ns15:value>
<ns15:configID>jdbcds.distinct</ns15:configID>
</ns15:attribute></ns19:attribute></ns19:attribute>
6. TDVサーバを再起動し、DISTINCT句がプッシュダウンされていることを確認します。
COUNT(DISTINCT [カラム名]) の場合
COUNT(DISTINCT [カラム名])
の形式では前述の手順でプッシュダウンできない場合があります。
以下の手順でCOUNT(DISTINCT [カラム名])
のプッシュダウンを行います。
1. アダプタの設定ファイルが存在する以下のパスに移動します。
[TDV Serverインストールフォルダ]\conf\adapters\system\[アダプタ名]
カスタムJDBCアダプタの場合は以下のパスに移動します。
[TDV Serverインストールフォルダ]\conf\adapters\custom\[アダプタ名]
2. <adapter name>_values.xml
というファイル名形式のファイルをテキストエディタなどで開きます。
3. 以下の内容をファイル先頭から4行目あたり、Please insert customized elements after this line.
のコメント下に記入しまします。
本手順の場合は以下の通りとなります。
<!-- Please insert customized elements after this line. -->
<ns38:attribute xmlns:ns38="http://www.compositesw.com/services/system/util/common">
<ns38:name>/runtime/query/Count</ns38:name>
<ns38:type>STRING</ns38:type>
<ns38:value>COUNT($1)</ns38:value>
<ns38:configID>COUNT(~[カラムのデータ型])</ns38:configID>
</ns38:attribute>
<ns39:attribute xmlns:ns39="http://www.compositesw.com/services/system/util/common">
<ns39:name>/runtime/query/CountDistinct</ns39:name>
<ns39:type>STRING</ns39:type>
<ns39:value>COUNT(DISTINCT $1)</ns39:value>
<ns39:configID>COUNT(~[カラムのデータ型]).distinct</ns39:configID>
</ns39:attribute>
複数のデータ型を指定することも可能です。
<ns38:attribute xmlns:ns38="http://www.compositesw.com/services/system/util/common">
<ns38:name>/runtime/query/CountNum</ns38:name>
<ns38:type>STRING</ns38:type>
<ns38:value>COUNT($1)</ns38:value>
<ns38:configID>COUNT(~number)</ns38:configID>
</ns38:attribute>
<ns39:attribute xmlns:ns39="http://www.compositesw.com/services/system/util/common">
<ns39:name>/runtime/query/CountDistincNum</ns39:name>
<ns39:type>STRING</ns39:type>
<ns39:value>COUNT(DISTINCT $1)</ns39:value>
<ns39:configID>COUNT(~number).distinct</ns39:configID>
</ns39:attribute>
<ns40:attribute xmlns:ns40="http://www.compositesw.com/services/system/util/common">
<ns40:name>/runtime/query/CountNum</ns40:name>
<ns40:type>STRING</ns40:type>
<ns40:value>COUNT($1)</ns40:value>
<ns40:configID>COUNT(~number)</ns40:configID>
</ns40:attribute>
<ns41:attribute xmlns:ns41="http://www.compositesw.com/services/system/util/common">
<ns41:name>/runtime/query/CountDistinctStr</ns41:name>
<ns41:type>STRING</ns41:type>
<ns41:value>COUNT(DISTINCT $1)</ns41:value>
<ns41:configID>COUNT(~string).distinct</ns41:configID>
</ns41:attribute>
3. TDVサーバを再起動し、COUNT(DISTINCT [カラム名])
がプッシュダウンされていることを確認します。