
from BaseDataMaintenance.dataSource.source import getConnect_ots
from BaseDataMaintenance.model.ots.attachment import attachment
from tablestore import *
from BaseDataMaintenance.common.Utils import *

def setStatus():
    ots_client = getConnect_ots()

    bool_query = BoolQuery(must_queries=[TermQuery("status",10)
                                         #,TermQuery("attachmentcon","")
                                         ])
    rows,next_token,total_count,is_all_succeed = ots_client.search("attachment","attachment_index",
                                                                   SearchQuery(bool_query,sort=Sort(sorters=[FieldSort("crtime",SortOrder.ASC)]),limit=100,get_total_count=True),
                                                                   columns_to_get=ColumnsToGet(["status","attachmentcon"],ColumnReturnType.SPECIFIED))


    print("total_count:",total_count)
    _count = 0
    _index = 0
    for _d in getRow_ots(rows):
        _index += 1
        if _d.get("attachmentcon","").strip()=="":
            _count += 1
    while True:
        if not next_token:
            break
        rows,next_token,total_count,is_all_succeed = ots_client.search("attachment","attachment_index",
                                                                       SearchQuery(bool_query,next_token=next_token,limit=100,get_total_count=True),
                                                                       columns_to_get=ColumnsToGet(["status","attachmentcon"],ColumnReturnType.SPECIFIED))


        print("%d/%d"%(_index,total_count))
        _count = 0
        for _d in getRow_ots(rows):
            _index += 1
            if _d.get("attachmentcon","").strip()=="":
                _count += 1

    print(_count)

from BaseDataMaintenance.model.ots.BaseModel import BaseModel
class ta(BaseModel):

    def __init__(self,_dict):
        for k,v in _dict.items():
            self.setValue(k,v,True)
        self.table_name = "test"

    def getPrimary_keys(self):
        return ["uuid"]

    def delete_row(self,ots_client):
        raise NotImplementedError()

def test():
    ots_client = getConnect_ots()
    _dict = {"uuid":"5","a2":"2","a3":"3"}
    a = ta(_dict)
    a.update_row(ots_client)

if __name__=="__main__":
    # setStatus()
    test()