将表部署到表存储中的最佳方法 [英] Best approach to deploy tables into table storage

查看:59
本文介绍了将表部署到表存储中的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我知道,什么是进行表存储部署的最佳方法,因为我的开发团队要求他们有很多表,每个表都有成千上万个条目.因此,他们要我咨询任何微软团队或博客人员正在检查进行表存储部署的最佳方法.您知道我们该怎么做,因为脚本每次都会消耗并插入数千个条目.

Will you let me know,what is the best way to do table storage deployment as my dev team is asking like that they have many tables of which each table is having thousands of entries.Hence,they are asking me to consult any microsoft team or blog people to check the best way to do table storage deployment.Do you have idea how we can do as the scripts will be doing depleting and inserting thousand of entries everytime.

我们是否有任何增量方法,如它将首先检查所有表条目,如果存在,则应仅将开发人员正在添加到csv文件中的新添加的条目附加到那些条目,我们只需要将其更新到表中即可存储.就是这样.这是一种方法.您有没有最好的方法.请帮助我.

do we have any delta approach like it will first check all the tables entries and if existed then it should just append the newly added entries which are being added into the csv files by dev team those entries only we need to update into table storage.that's it.this is one approach.Do you have any best possible approach.Please kindly help me.

推荐答案

There is InsertOrReplace(ITableEntity) method in TableBatchOperation Class that can do batch operation with ExecuteBatch method, try it with this code:

         param(
                 [object[]]$fileObj
                )

            $storageAccountName = "XXX"

            $tableName="XXX"

            # Get the storage key for the storage account
            $StorageAccountKey = "XXX"

            # Get a storage context
            $ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey

            foreach($fo in $fileObj){
             Write-Host $fo.filepath
             $csv = Import-CSV $fo.filepath
              $cArray=$fo.Cols.split(",")
        $table = Get-AzureStorageTable -Name $fo.tableName -Context $ctx -ErrorAction Ignore
              [Microsoft.WindowsAzure.Storage.Table.TableBatchOperation]$batchOperation = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.TableBatchOperation

if($table)
{
Write-Host "table not null"
}
else
{
Write-Host "table is null"
}
if($table.CloudTable)
{
Write-Host "CloudTable not null"
}
else
{
Write-Host "CloudTable is null"
}

foreach($line in $csv)
                {

                Write-Host "$($line.partitionkey), $($line.rowKey)"
                $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity -ArgumentList $line.partitionkey, $line.rowKey 
                    foreach($c in $cArray){
                 Write-Host "$c,$($line.$c)"
                    $entity.Properties.Add($c,$line.$c)
             $batchOperation.Insert($entity)

                    }       
             }
if($batchOperation)
{
Write-Host "batchOperation not null"
}
else
{
Write-Host "batchOperation is null"
}
    $table.CloudTable.ExecuteBatch($batchOperation)
            }

这篇关于将表部署到表存储中的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆