

from BaseDataMaintenance.model.ots.BaseModel import BaseModel

document_extract2_partitionkey = "partitionkey"
document_extract2_docid = "docid"
document_extract2_extract_json = "extract_json"
document_extract2_industry_json = "industry_json"
document_extract2_other_json = "other_json"
document_extract2_status = "status"
document_extract2_save = "save"
document_extract2_already_storage = "already_storage"

class Document_extract2(BaseModel):

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

    def getPrimary_keys(self):
        return ["partitionkey","docid"]

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

class Document_extract(BaseModel):

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

    def getPrimary_keys(self):
        return ["partitionkey","docid"]

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


if __name__ == '__main__':

    from BaseDataMaintenance.dataSource.source import getConnect_ots
    from tablestore import *
    from BaseDataMaintenance.common.Utils import *

    ots_client = getConnect_ots()
    bool_query = BoolQuery(must_queries=[RangeQuery("docid",1)])
    rows,next_token,total_count,is_all_succeed = ots_client.search("document_extract","document_extract_index",
                                                                   SearchQuery(bool_query,sort=Sort(sorters=[FieldSort("docid")]),limit=100,get_total_count=True),
                                                                   ColumnsToGet(return_type=ColumnReturnType.ALL))
    list_data = getRow_ots(rows)
    for _data in list_data:
        extract_json = _data["extract_json"]
        extract_json = re.sub("\\\\n","",extract_json)
        extract_json = re.sub("\\\\","",extract_json)
        de = Document_extract(_data)
        de.setValue("extract_json",extract_json,True)
        de.update_row(ots_client)
    while next_token:
        rows,next_token,total_count,is_all_succeed = ots_client.search("document_extract","document_extract_index",
                                                                       SearchQuery(bool_query,next_token=next_token,limit=100,get_total_count=True),
                                                                       ColumnsToGet(return_type=ColumnReturnType.ALL))
        list_data = getRow_ots(rows)
        for _data in list_data:
            extract_json = _data["extract_json"]
            extract_json = re.sub("\\\\n","",extract_json)
            extract_json = re.sub("\\\\","",extract_json)
            de = Document_extract(_data)
            de.setValue("extract_json",extract_json,True)
            de.update_row(ots_client)


