问题
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.
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.
回答1:
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)
}
来源:https://stackoverflow.com/questions/47091334/best-approach-to-deploy-tables-into-table-storage