Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda