CLI for BCP (SQL SVR) and dynamic file names
The scenario I needed to accomplish was to pull data from SQL server, group the data sets together based on different fields and then dynamically define the file name based on those groupings. Performance was the #1 consideration and competitive tool sets were able to complete the action in under 2 hours with a 300M record set. For my testing and documentation below, I’m using a local data set of 3.6M records. Initial attempts at using the SQL Read and SQL Execute snaps quickly excluded those based on required throughput (was getting somewhere between 12k and 18k records per second over the network, 26k records per second local). Calculated out, that would have taken 7-10 hours just for the query to complete. The final solution ended up being broken down into 3 main steps: Command line execution to call a BAT file which invokes the BCP command Reading the dataset created from step 1 and performing the GROUP BY and a mapper to prep the data Document2Binary snap and then a file write which utilizes the $[‘content-location’] value to dynamical set the name. Attached to this post is the ZIP export of the project which contains 3 pipelines along with a SAMPLE bat file which starts the bcp utility. You will need to edit the bat file for your specific database requirements, the pipeline parameter for where the output of the bat file is stored and the location of the file you want written out. Pipeline: 1_Run_BCP_CLI NOTE: There is a pipeline parameter for the BCP output file that gets generated ‘Reference to BAT’ - points to a file on the local drive which executes the actual BCP process. (My files are located in c:\temp\bcp_testing) ‘DEL BCP Out’ will delete the bcp file if it already exists (optional as the bcp process will just overwrite the file anyway) ‘cli to run’ is renaming the bat key value (originally done as I was testing the cli and bcp execute - could be removed) ‘remove nulls’ will clear out the results from the ‘DEL BCP Out’ since it’s not part of the command line that needs to be executed. ‘Execute CLI’ is a script snap which will kick off the bat file and once completed, return a single record with the results. ‘Process BCP’ Out’ is a pipeline execute which calls 2_BULK_DAT_READ and passes the pipeline parameter for the file to read in the next step Pipeline: 2_BULK_DAT_READ ‘BCP Out File Read’ will use the pipeline parameter value specified for which file to read ‘CSV Parser’ self explanatory - does NOT have any headers on the data file (to enhance the pipeline, you could add the second input and define the file format with column names and types) ‘Group by Fields’ takes the first 2 field names (field001 and field002) and will create groupings for each set. This is the results of the initials for both first and last name from the BCP SQL Query. ‘Mapper’ will convert the JSON payload to $content as well as define $[‘content-location’] based on the grouped by fields. The expression is $groupBy.field001+"_"+$groupBy.field002 ‘Pipeline Execute’ will provide both $content and $[‘content-location’] to the next pipeline Pipeline: 3_DynamicFile_Write ‘Document to Binary’ with the option for ‘Document’ as the Encode or Decode setting allows the JSON records to be output as a binary stream. ‘File Writer’ will build the protocol, folder specification and the file name based on the provided $[‘content-location’] value from before. Execution Results The 3.6M records were actually processed in 16 seconds. The BCP process itself took 24 seconds. My group by was based on the first characters on both First name and Last name. This process ended up creating 294 files (locally) and used the naming convention of _.json Sample screen cap of the A_A.json file: Notes and File The file created contains a KEY for ‘content’ and is not pretty print json. For the screen cap above, I’m utilizing the JSTool → JSFormat plug-in for Notepad++. This approach will only create JSON formatted data (not CSV or other formatter options) BCP is required to be installed and this was only tested on a WINDOWS groundplex EricBarner-SQLSvr_BCP_CLI_Community.zip (4.4 KB)5.7KViews4likes2CommentsCommon Error Handler
Hi, As requested in another thread, here is our common error handler which we’re trying to use across all projects. Feel free to share your own and any ideas! Here is the screenshot (pipeline definition is attached below): Key features: We have multiple potential notification mechanisms - currently e-mail and/or ServiceNow We have the option for either critical failures (fails the parent Pipeline) or non-critical (send error notification but does not fail the parent) We use a parameters file to configure error behavior for each calling/parent pipeline so that this can be changed for each environment (including things like the e-mail recipients) Parameters are also driven by an ‘error code’ which is passed in from the parent - this allows us to have different error behavior in different section / scenarios of the parent pipeline It is up to the pipeline designer to correctly map the document data which is input into the error handler, including identifying the relevant data to include in the message (e.g. the unique identified of the record which is in error). The package below includes the error handler, the parameters file and an example demonstrating its use. ErrorHandler.zip (6.8 KB) Cheers, C.J.3.2KViews4likes0CommentsDetecting schema change
Here are two pipelines that everyone can relate to. Detecting schema change in an upstream data source (SQL Server in this example) and identifying the exact nature of change. Also check out our blog post on this topic. SchemaChange_SaveOriginal.slp (5.7 KB) SchemaChangeDetection_Compare.slp (39.6 KB)2.3KViews3likes0CommentsMapper vs. JSON Splitter
Did you know that you can use the Mapper snap to the same effect as JSON Splitter? There are some other reasons why you may want to use JSON Splitter. First of all let’s look at how mapper can achieve similar functionality of JSON Splitter To achieve the same split, in the mapper, just drag the array into the left hand expression and map it to $ in the right hand side target path. Basically this will split the array elements into the outgoing documents. Using JSON Splitter however, you get additional benefits of including scalar parents as well as including different output paths as part of the split. Attached is an example (simple one of course). json split vs mapper_2017_08_08.slp (7.1 KB)4.5KViews2likes0CommentsDesigning a pipeline to route depending if there is or is not data in an initial query
Hi, I am trying to design a pipeline where it initially will pull in a query result set. I am trying to create a route that identifies whether the query result set returned records or did not return records. Any idea on how to design this pipeline?2.3KViews1like2CommentsError in Snowflake Bulk Load
Hello, I have a parent and child pipeline where the parent pipeline sends some venue details to child pipeline. Based on the venue details, the child pipeline calls a REST GET to acquire data from vendor and loads into Snowflake table using Snowflake BULK LOAD Snap. one of the child pipelines failed with the below mentioned error “Exception caught in HTTP_EXECUTE_THREAD, aborting HTTP request”. Normally this pipeline would take 15 to 20 secs to complete, but it took 16 mins and failed with the below error. Any help to figure out the cause of error would be highly appreciated. Thanks Aravind N1.6KViews1like0CommentsAdditional Blank Spaces are removed automatically
Hello Experts. While forming string with additional blank spaces which is required in out put string is getting trimmed automatically. Any additional setting or expression do i need to mention to preserve the spaces ? how can I specify next line in Fixed Width Formatter Snap if second line has different line configuration then first line format? Regards, Ajay1.4KViews1like0CommentsRead Access key from Azure Key vault
Hi, Is there any way to connect to Azure key vault and read access key information from there? I have requirement to that keys are going to be roated frequently and keys are going to be stored in Azure key vault. So I wanted to read recent access key for connecting to Azure storage. Thanks, Gowdhaman