public IExportTableArchive GetInitializedTableExportTask() { // Determine server name from connection string // This is required, because bulk copy can go into databases that are only known // by their connection string // Get server name from data source name (requires trimming the sql server instance name) string host = ((Jhu.Graywulf.Schema.SqlServer.SqlServerDataset)sources[0].Dataset).Host; var ss = new SourceTableQuery[sources.Length]; for (int i = 0; i < sources.Length; i++) { ss[i] = new SourceTableQuery() { Dataset = sources[i].Dataset, Query = String.Format("SELECT t.* FROM [{0}].[{1}] AS t", sources[i].SchemaName, sources[i].ObjectName) }; } // Create bulk operation var te = RemoteServiceHelper.CreateObject <IExportTableArchive>(host); te.Sources = ss; te.Destinations = destinations; te.Uri = uri; te.FileFormatFactoryType = fileFormatFactoryType; te.StreamFactoryType = streamFactoryType; te.Timeout = timeout; return(te); }
protected void ExecuteInsertInto(SourceTableQuery source, Table destination, int timeout) { string sql = String.Format( "INSERT [{0}].[{1}].[{2}] WITH (TABLOCKX) SELECT __tablealias.* FROM ({3}) AS __tablealias", !String.IsNullOrWhiteSpace(destination.DatabaseName) ? destination.DatabaseName : destination.Dataset.DatabaseName, destination.SchemaName, destination.TableName, source.Query); ExecuteLongCommandNonQuery(sql, source.Dataset.ConnectionString, timeout); }
/// <summary> /// Creates and initializes a remote or local table copy task /// </summary> /// <param name="source"></param> /// <param name="destination"></param> /// <param name="local"></param> /// <returns></returns> protected ICopyTable CreateTableCopyTask(SourceTableQuery source, DestinationTable destination, bool local) { var desthost = GetHostnameFromSqlConnectionString(destination.Dataset.ConnectionString); ICopyTable qi; if (local) { qi = new CopyTable(); } else { qi = RemoteServiceHelper.CreateObject <ICopyTable>(desthost); } qi.Source = source; qi.Destination = destination; return(qi); }
/// <summary> /// Copies a table from a remote data source by creating and /// executing a table copy task. /// </summary> /// <param name="table"></param> /// <param name="source"></param> public void CopyRemoteTable(TableReference table, SourceTableQuery source) { // Create a target table name var temptable = GetTemporaryTable(GetEscapedUniqueName(table)); TemporaryTables.TryAdd(table.UniqueName, temptable); var dest = new DestinationTable(temptable) { Options = TableInitializationOptions.Drop | TableInitializationOptions.Create }; var tc = CreateTableCopyTask(source, dest, false); var guid = Guid.NewGuid(); RegisterCancelable(guid, tc); tc.Execute(); UnregisterCancelable(guid); }
private void OnAsyncExecute(Guid workflowInstanceGuid, string activityInstanceId, QueryPartitionBase querypartition, TableReference remotetable, SourceTableQuery source) { RegisterCancelable(workflowInstanceGuid, activityInstanceId, querypartition); querypartition.CopyRemoteTable(remotetable, source); UnregisterCancelable(workflowInstanceGuid, activityInstanceId, querypartition); }