すべてのプロダクト
Search
ドキュメントセンター

Tablestore:フィルター

最終更新日:May 12, 2026

Tablestore はサーバー側でのフィルタリングをサポートしており、指定した条件に一致するデータのみを返します。本トピックでは、Node.js SDK でフィルターを使用する方法について説明します。

前提条件

Tablestore クライアントの初期化

フィルターの種類

Tablestore には以下の 2 種類のフィルターがあります。

  • SingleColumnCondition:単一の属性列の値に基づいてデータをフィルタリングします。

  • CompositeCondition:複数のフィルター条件を組み合わせます。

SingleColumnCondition

TableStore.SingleColumnCondition

パラメーター

パラメーター

説明

comparator (必須)

TableStore.ComparatorType

関係演算子。有効な値は、EQUAL、NOT_EQUAL、GREATER_THAN、GREATER_EQUAL、LESS_THAN、および LESS_EQUAL です。

columnName (必須)

string

フィルタリング対象の属性列の名前。

columnValue (必須)

STRING、INTEGER、BINARY、DOUBLE、BOOLEAN

比較対象の値。

passIfMissing (オプション)

boolean

true の場合、指定された属性列が存在しない行も返されます。デフォルト値は true です。

latestVersionOnly (オプション)

boolean

true の場合、属性列の最新バージョンのデータのみを評価します。デフォルト値は true です。

以下の例では、プライマリキーの値が [row1, row3) の範囲内にあるデータに対して範囲クエリを実行し、さらにフィルターを適用して、属性列 col1 の値が val1 である行のみを返します。

var params = {
    tableName: 'test_table',
    // クエリの開始プライマリキーを設定します。
    inclusiveStartPrimaryKey: [{ 'id': 'row1' }],
    // クエリの終了プライマリキーを設定します(排他的)。
    exclusiveEndPrimaryKey: [{ 'id': 'row3' }]
};
// 条件 col1 == "val1" を持つフィルターを構築します。
var singleColumnCondition = new TableStore.SingleColumnCondition('col1', 'val1', TableStore.ComparatorType.EQUAL);
params.columnFilter = singleColumnCondition;

// getRange メソッドを呼び出してデータをクエリします。
client.getRange(params, function (err, data) {
    if (err) {
        console.log('Range get failed with error: ', err);
        return;
    }

    // 応答を処理します。
    console.log('* RequestId: ', data.RequestId);
    console.log('* Read CU Cost: ', data.consumed.capacityUnit.read);
    console.log('* Write CU Cost: ', data.consumed.capacityUnit.write);
    console.log('* Rows Data: ');
    data.rows.forEach(function (row) {
         console.log(row);
    });
});
  • 指定された属性列が存在しない行を除外するには、passIfMissing を false に設定します。

    singleColumnCondition.passIfMissing = false;
  • すべてのデータバージョンを評価するには、latestVersionOnly を false に設定します。いずれかのバージョンが条件を満たす場合、その行が返されます。

    singleColumnCondition.latestVersionOnly = false

CompositeCondition

最大 32 個の条件を組み合わせることができます。

TableStore.CompositeCondition

パラメーター

パラメーター

説明

combinator (必須)

TableStore.LogicalOperator

論理演算子。有効な値は、NOT、AND、および OR です。

sub_conditions (必須)

Array

組み合わせる条件の配列。SingleColumnCondition および CompositeCondition オブジェクトを含めることができます。

以下の例では、プライマリキーの値が [row1, row3) の範囲内にある行に対して範囲クエリを実行し、その後、複合フィルターを適用します。

var params = {
    tableName: 'test_table',
    // 開始プライマリキーを設定します。
    inclusiveStartPrimaryKey: [{ 'id': 'row1' }],
    // 終了プライマリキーを設定します(排他的)。
    exclusiveEndPrimaryKey: [{ 'id': 'row3' }]
};

// 最初の単一列条件を構築します:col1 == "val1"。
var singleColumnCondition1 = new TableStore.SingleColumnCondition('col1', 'val1', TableStore.ComparatorType.EQUAL);
// 2 番目の単一列条件を構築します:col2 == "val2"。
var singleColumnCondition2 = new TableStore.SingleColumnCondition('col2', 'val2', TableStore.ComparatorType.EQUAL);
// 最初の複合条件を構築します:col1 == "val1" OR col2 == "val2"。
var compositeCondition1 = new TableStore.CompositeCondition(TableStore.LogicalOperator.OR);
compositeCondition1.addSubCondition(singleColumnCondition1);
compositeCondition1.addSubCondition(singleColumnCondition2);
// 3 番目の単一列条件を構築します:col3 == "val3"。
var singleColumnCondition3 = new TableStore.SingleColumnCondition('col3', 'val3', TableStore.ComparatorType.EQUAL);
// 2 番目の複合条件を構築します:(col1 == "val1" OR col2 == "val2") AND col3 == "val3"。
var compositeCondition2 = new TableStore.CompositeCondition(TableStore.LogicalOperator.AND);
compositeCondition2.addSubCondition(compositeCondition1);
compositeCondition2.addSubCondition(singleColumnCondition3);
// クエリにフィルターを追加します。
params.columnFilter = compositeCondition2

// getRange メソッドを呼び出してデータをクエリします。
client.getRange(params, function (err, data) {
    if (err) {
        console.log('Range get failed with error: ', err);
        return;
    }

    // 応答を処理します。
    console.log('* RequestId: ', data.RequestId);
    console.log('* Read CU Cost: ', data.consumed.capacityUnit.read);
    console.log('* Write CU Cost: ', data.consumed.capacityUnit.write);
    console.log('* Rows Data: ');
    data.rows.forEach(function (row) {
         console.log(row);
    });
});

関連トピック