Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
GCP Dataflow UDF import files

I'm using the PubSub to Elastic Dataflow template and I need to do some enrichment, like XML parsing.

I have two issues:

  1. Can I split my code into many files and import them using UDF and how?
  2. Can I install external libraries? I read only plain js files are supported, but then read this article and I'm not sure if applies to Dataflow UDFs or how to implement it: https://medium.com/analytics-vidhya/using-npm-library-in-google-bigquery-udf-8aef01b868f4

Any guidance would be appreciated.

Thanks

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I was almost there. I wasnt building the single js file properly.

src/index.js

var convert = require("xml-js");

module.exports.data_process = function (inJson) {
  var xml = "<XML CONTENT>";
  var result1 = convert.xml2json(xml, { compact: true, spaces: 4 });
  var parsed = JSON.parse(result1);
  var some_field = parsed.some.field
  var obj = JSON.parse(inJson);
  obj.some_field = some_field;
  return JSON.stringify(obj);
};

webpack.config.js

const path = require("path");

module.exports = {
  entry: "./src/index.ts",
  mode: "production",
  output: {
    filename: "main.js",
    path: path.resolve(__dirname, "dist"),
    library: "xmllib",
  },
};

build webpack

npx webpack --config webpack.config.js

Then add to the end of main.js

function process(d) {
    c = xmllib.data_process(d);
    return c;
}

Now you can use "process" as your dataflow udf function name.

Solution based on this article: https://blog.salrashid.dev/articles/2020/bq-udf-protobuf/

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!