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

192
Vistas
How to pass input from user to a java script function inside a snowflake UDF?

I have to convert some JS functions to snowflake udfs. It works successfully with hardcoded sample data but I can't make it accept user input as arguments. I know the UDF's create statement is supposed to take the input but I cannot make it work.

CREATE OR REPLACE FUNCTION findAndReplace()
  RETURNS variant 
  LANGUAGE JAVASCRIPT
AS
$$
  return execute(map,value); 
  $$
 ;
 
 select findAndReplace();

Thanks for the help.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Assuming that arguments to provide are inside map.set("SKU","Common Measurement (L x W)^Manufacturer Color/Finish"); the function signature has to be changed to findAndReplace(ARG1 TEXT, ARG2 TEXT):

CREATE OR REPLACE FUNCTION findAndReplace(ARG1 TEXT, ARG2 TEXT)
  RETURNS variant 
  LANGUAGE JAVASCRIPT
AS
$$
const execute = (productMap, values) => {
  const split = values.split(",");
  const value = productMap.get(split[0]);
  try {
      if (split.length > 2) {
          if (value != null) {
              const from = split[1].replaceAll("\'", "");
              const to = split[2].replaceAll("\'", "");
              return value.replaceAll(from,to);
          }
      }
  }catch{
      console.log("Error in executing FindAndReplace Rule ");
  }
  return "n/a";
}

//Example
  var map = new Map()
  map.set(ARG1, ARG2);   // <-- HERE
  const value = "SKU,'Color/','#'";
  return execute(map,value); 
  $$
 ;

Function all:

select findAndReplace('SKU', 'Common Measurement (L x W)^Manufacturer Color/Finish');
about 4 years ago · Juan Pablo Isaza 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