Tüm Ürünler
Search
Belge Merkezi

Tablestore:Filters

Son Güncelleme:Oct 02, 2026

Tablestore'da belirtilen koşullara göre sunucu tarafındaki sorgu sonuçlarını iyileştirmek için filtreleri kullanabilirsiniz. Bu konuda .NET SDK'da filtrelerin nasıl kullanılacağı açıklanmaktadır.

Önkoşullar

Tablestore istemcisini başlatın

Filtre türleri

Tablestore aşağıdaki iki filtre türünü sunar.

  • RelationalCondition: Tek bir nitelik sütununun değerinin belirli bir koşulu karşılayıp karşılamadığını belirler.

  • CompositeCondition: Verileri filtrelemek amacıyla birden fazla koşulu birleştirir.

RelationalCondition

public class RelationalCondition : IColumnCondition

Parametreler


Parametre


Tür


Açıklama


Operator (Zorunlu)


CompareOperator


İlişkisel operatör. Desteklenen operatörler EQUAL, NOT_EQUAL, GREATER_THAN, GREATER_EQUAL, LESS_THAN ve LESS_EQUAL değerleridir.


ColumnName (Zorunlu)


string


Değerlendirilecek nitelik sütununun adı.


ColumnValue (Zorunlu)


ColumnValue


Karşılaştırma yapılacak değer.


PassIfMissing (İsteğe bağlı)


bool


Belirtilen nitelik sütunu eksik olan bir satırın döndürülüp döndürülmeyeceğini kontrol eder. Varsayılan değer true ise satır döndürülür.


LatestVersionsOnly (İsteğe bağlı)


bool


Birden fazla sürüm mevcut olsa bile yalnızca bir nitelik sütununun en son veri sürümünün değerlendirilip değerlendirilmeyeceğini belirtir. Varsayılan değer true değeridir.

Örnek

Bu örnekte birincil anahtarı [row1, row3) aralığında bulunan satır verileri için bir aralık sorgusu çalıştırılır. Sorgu daha sonra yalnızca col1 nitelik sütunu val1 olan satırları döndürmek üzere bir filtre uygular.

try
{
    // Set the start primary key for the query.
    PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey()
    {
        { "id", new ColumnValue("row1") }
    };
    // Set the end primary key for the query. The end key is exclusive.
    PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey()
    {
        { "id", new ColumnValue("row3") }
    };
    // Create a filter with the condition: col1 == "val1".
    RelationalCondition relationalCondition = new RelationalCondition("col1", CompareOperator.EQUAL, new ColumnValue("val1"));

    // Call the GetRange method to read row data.
    GetRangeRequest getRangeRequest = new GetRangeRequest("test_table", GetRangeDirection.Forward, inclusiveStartPrimaryKey, exclusiveEndPrimaryKey, null, null, relationalCondition);
    GetRangeResponse getRangeResponse = client.GetRange(getRangeRequest);

    // Process the response.
    Console.WriteLine($"RequestId: {getRangeResponse.RequestID}");
    Console.WriteLine($"Read CU Cost: {getRangeResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"Write CU Cost: {getRangeResponse.ConsumedCapacityUnit.Write}");
    Console.WriteLine("Row Data: ");
    foreach (Row row in getRangeResponse.RowDataList)
    {
        Console.WriteLine(row);
    }
}
catch (Exception ex)
{
    Console.WriteLine($"Get Range failed, exception: {ex.Message}");
}
  • Belirtilen nitelik sütunu eksik olan bir satırı hariç tutmak için PassIfMissing parametresini false olarak ayarlayın.

    relationalCondition.PassIfMissing = false;

CompositeCondition

En fazla 32 koşulu birleştirebilirsiniz.

public class CompositeCondition : IColumnCondition

Parametreler


Parametre


Tür


Açıklama


LogicOperator (Zorunlu)


LogicOperator


Mantıksal operatör. Desteklenen operatörler NOT, AND ve OR değerleridir.


subConditions (Zorunlu)


List<IColumnCondition>


Mantıksal operatör kullanılarak birleştirilecek filtrelerin listesi. Liste hem RelationalCondition hem de CompositeCondition nesnelerini içerebilir.

Örnek

Bu örnek birincil anahtarı [row1, row3) aralığında bulunan satır verileri için bir aralık sorgusunun nasıl çalıştırılacağını gösterir. Ardından sonuçları filtrelemek amacıyla bir CompositeCondition kullanılır.

try
{
    // Set the start primary key for the query.
    PrimaryKey inclusiveStartPrimaryKey = new PrimaryKey()
    {
        { "id", new ColumnValue("row1") }
    };
    // Set the end primary key for the query. The end key is exclusive.
    PrimaryKey exclusiveEndPrimaryKey = new PrimaryKey()
    {
        { "id", new ColumnValue("row3") }
    };

    // Create RelationalCondition 1: col1 == "val1".
    RelationalCondition relationalCondition1 = new RelationalCondition("col1", CompareOperator.EQUAL, new ColumnValue("val1"));
    // Create RelationalCondition 2: col2 == "val2".
    RelationalCondition relationalCondition2 = new RelationalCondition("col2", CompareOperator.EQUAL, new ColumnValue("val2"));
    // Create CompositeCondition 1: col1 == "val1" OR col2 == "val2".
    CompositeCondition compositeCondition1 = new CompositeCondition(LogicOperator.OR);
    compositeCondition1.AddCondition(relationalCondition1);
    compositeCondition1.AddCondition(relationalCondition2);
    // Create RelationalCondition 3: col3 == "val3".
    RelationalCondition relationalCondition3 = new RelationalCondition("col3", CompareOperator.EQUAL, new ColumnValue("val3"));
    // Create CompositeCondition 2, which combines the previous conditions: (col1 == "val1" OR col2 == "val2") AND col3 == "val3".
    CompositeCondition compositeCondition2 = new CompositeCondition(LogicOperator.AND);
    compositeCondition2.AddCondition(compositeCondition1);
    compositeCondition2.AddCondition(relationalCondition3);

    // Call the GetRange method to read row data.
    GetRangeRequest getRangeRequest = new GetRangeRequest("test_table", GetRangeDirection.Forward, inclusiveStartPrimaryKey, exclusiveEndPrimaryKey, null, null, compositeCondition2);
    GetRangeResponse getRangeResponse = client.GetRange(getRangeRequest);

    // Process the response.
    Console.WriteLine($"RequestId: {getRangeResponse.RequestID}");
    Console.WriteLine($"Read CU Cost: {getRangeResponse.ConsumedCapacityUnit.Read}");
    Console.WriteLine($"Write CU Cost: {getRangeResponse.ConsumedCapacityUnit.Write}");
    Console.WriteLine("Row Data: ");
    foreach (Row row in getRangeResponse.RowDataList)
    {
        Console.WriteLine(row);
    }
}
catch (Exception ex)
{
    Console.WriteLine($"Get Range failed, exception: {ex.Message}");
}

İlgili konular