marklogicml-gradle

How to pass parameter value to gradle mlExportToFile transform module


I am currently using mlExportToFile to export JSON documents to a single file. I would like to pass a parameter value from my shell script to the transform module. By default, the transform module function (as created by gradle mlCreateTransform -PtransformName=CustomerTransform -PtransformType=sjs) takes 3 variables as inputs - context, params, and content. However, when defining params, as seen in the script below, the value is not being sent to the transform function.

querydate=$(<DeltaTimestamp.txt)
querydate1="${querydate}.000000Z"
gradle mlExportToFile -PexportPath=/tgtfiles/my_file.json -Ptransform=CustomerTransform -PwhereUrisQuery='cts.andQuery([cts.collectionQuery("latest"),cts.collectionQuery("customer")])' -Pparams='{"querydate1":"'"$querydate1"'"}' 

Solution

  • If you run just "./gradlew mlExportToFile", you'll get the "help" text for the task. That includes the following:

    transform: The name of a REST transform to apply to each record. Parameters can be passed to the transform by appending them to the value of this property, delimited by commas - e.g. myTransform,param1,value1,param2,value2

    Thus, you can append parameter names and values to the "-Ptransform=CustomerTransform" argument - e.g. "-Ptransform=CustomerTransform,param1,value1,param2,value2".