Пример #1
0
def batch_entry():
    batch = TableBatch()
    order004 = {
        'PartitionKey': 'ordersSeattle',
        'RowKey': '004',
        'description': 'Go grocery shopping',
        'priority': 400
    }
    order005 = {
        'PartitionKey': 'ordersSeattle',
        'RowKey': '005',
        'description': 'Clean the bathroom',
        'priority': 100
    }
    batch.insert_entity(order004)
    batch.insert_entity(order005)
    table_service.commit_batch('ordertable', batch)

    order006 = {
        'PartitionKey': 'ordersSeattle',
        'RowKey': '006',
        'description': 'Go grocery shopping',
        'priority': 400
    }
    order010 = {
        'PartitionKey': 'ordersSeattle',
        'RowKey': '007',
        'description': 'Clean the bathroom',
        'priority': 100
    }

    with table_service.batch('ordertable') as batch:
        batch.insert_entity(order006)
        batch.insert_entity(order007)
Пример #2
0
def upload_data_to_azure(table_service):
    global data

    # Create table if it doesn't exist
    table_service.create_table(dataset_table_name, fail_on_exist=False)

    batch = TableBatch()

    for d in data:
        batch.insert_entity(d)

    table_service.commit_batch(dataset_table_name, batch)
    data = []
Пример #3
0
def update_table_storage_based_on_new_data(subscription_id,
                                           non_compliant_resources,
                                           non_compliant_ids_to_add,
                                           non_compliant_ids_to_delete,
                                           table_service):
    """
    Makes a batch update by adding / deleting rows from the table storage
    """
    batch = TableBatch()

    for ncr in non_compliant_resources:
        if ncr['RowKey'] in non_compliant_ids_to_add:
            batch.insert_entity(ncr)

    for row_key in non_compliant_ids_to_delete:
        batch.delete_entity(subscription_id, row_key)

    table_service.commit_batch(RECOMMENDATIONS_TABLE_NAME, batch)
Пример #4
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Starting bulk insert.')
    ret = dict()

    table_name = req.headers.get('name')

    values = req.get_json()

    if table_name:
        retrieved_secret = getConnectionString()

        table_service = TableService(connection_string=retrieved_secret.value)
        batch = TableBatch()
        for i in range(0, len(values['rows'])):
            batch.insert_entity(values['rows'][i])

        table_service.commit_batch(table_name, batch)

        ret['result'] = "Success"
        return func.HttpResponse(json.dumps(ret), status_code=200)
    else:
        ret['result'] = 'Error'
        return func.HttpResponse(json.dumps(ret), status_code=400)
Пример #5
0
    def insert_batch(self, items: list):
        batch = TableBatch()
        for item in items:
            batch.insert_entity(self.get_payload(item))

        return self.table.commit_batch(self.table_name, batch)
Пример #6
0
)

batch = TableBatch()
task008 = {
    'PartitionKey': 'tasksTigard',
    'RowKey': '008',
    'description': 'Go grocery shopping',
    'priority': 400
}
task009 = {
    'PartitionKey': 'tasksTigard',
    'RowKey': '009',
    'description': 'Clean the bathroom',
    'priority': 100
}
batch.insert_entity(task008)
batch.insert_entity(task009)
table_service.commit_batch('tasktable', batch)

task010 = {
    'PartitionKey': 'tasksTigard',
    'RowKey': '010',
    'description': 'Go grocery shopping',
    'priority': 400
}
task011 = {
    'PartitionKey': 'tasksTigard',
    'RowKey': '011',
    'description': 'Clean the bathroom',
    'priority': 100
}
table_service.insert_or_replace_entity('tasktable', task)

# Insert a new entity
print("insert or replay rowkey 003 - buy detergent")
task = {'PartitionKey': 'tasksSeattle', 'RowKey': '003',
        'description': 'Buy detergent', 'priority': 300}
table_service.insert_or_replace_entity('tasktable', task)

# batch processing - Add multiple entries
print("batch processing task 004/005")
batch = TableBatch()
task004 = {'PartitionKey': 'tasksSeattle', 'RowKey': '004',
           'description': 'Go grocery shopping', 'priority': 400}
task005 = {'PartitionKey': 'tasksSeattle', 'RowKey': '005',
           'description': 'Clean the bathroom', 'priority': 100}
batch.insert_entity(task004)
batch.insert_entity(task005)
table_service.commit_batch('tasktable', batch)

# alternative way to use batch, using context
print("batch insert using context...")
task006 = {'PartitionKey': 'tasksSeattle', 'RowKey': '006',
           'description': 'Go grocery shopping', 'priority': 400}
task007 = {'PartitionKey': 'tasksSeattle', 'RowKey': '007', 'newCol': 'newColVal1',
           'description': 'Clean the bathroom', 'priority': 100}

with table_service.batch('tasktable') as batch:
    batch.insert_entity(task006)
    batch.insert_entity(task007)

# Query