Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda