npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cherre-elt-udf

v1.1.0

Published

## Documentation

Downloads

4

Readme

udf

Documentation

TODO

Environment variables

  • PROJECT_ID (required) Google Cloud Project ID.
  • CHERRE_GOOGLE_CREDENTIALS (required) Base64 encoded Google Cloud JSON key file
  • UDF_BUNDLE_GCS_URI (required) Google Cloud Storage URI to Javascript UDF function bundle

Development

Requirements

  • NodeJS v10 or later

Run

  • Install packages
#!bash

npm install
  • Setup environment variables Option 1 - Directly change environment variable
#!bash
export PROJECT_ID=cherre-sandbox
export UDF_BUNDLE_GCS_URI=gs://cherre-sandbox/bigquery_udf/my_dev_udf/bundle.js

Option 2 - Create .env file in the same folder within package.json

#.env
PROJECT_ID=cherre-sandbox
UDF_BUNDLE_GCS_URI=gs://cherre-sandbox/bigquery_udf/my_dev_udf/bundle.js
  • Run unit test in watch mode

Use npm ci instead of npm install in Dockerfiles (see https://docs.npmjs.com/cli/ci.html)

Adding new parsing function

Parsing functions are used in our ELT format by having all data loaded into big query as a single column. The parsing function then takes the single column and parses it into individual columns for further transformation.

Start with a test file

Add a test.js file under src/functitons/tests with the below format:

test('<SAMPLE ROW>', () => {
  expect(parseAvroll('<SAMPLE ROW>')).toMatchSnapshot()
})

You will provide your test with a sample row and it will apply your parsing function. The parsing function should create the output that matches the output in the snapshot in the /src/functions/test/__snapshots__ folder

Add snapshot test

the snapshot is an example of of how you will feed a row that needs to be parsed and you are expecting back a JSON object with key value pairs for column name and column data. Big Query will use this function on each row and return.

It is advised to copy a single from the raw ingested table and put it in to the exports. This example has commas as a seperator but your data may be seperated by tabs or pipes.

exports['Column 1 data,Column 2 data,Column 3 data'] = `
Object {
  "Column 1 Name": "Column 1 data",
  "Column 2 Name": "Column 2 data",
  "Column 3 Name": "Column 3 data"

 };`

Then fill in the names that correlate to the appropriate columns to show how you want the data to look.

Create snapshot function

Now that the tests are setup, you can create your javascript parsing function. Create a file with a function in it. The format should take in a single variable (convention is unparsed), apply the split function with whichever delimiter you use. (Attom uses pipe |) and return a const which will have each column named

Then run unit test in watch mode

#!bash

npm run test:unit:watch

If your tests pass you should be ready to deploy.

Deploy function

Run the following command to ensure that your javascript compiles correctly.

npm run udf

Once it compiles, add your function into the /src/bundle.js file as an import such as:

export { <your function> } from './functions/<your filename>'

Then run npm run udf:deploy to send the bundle.js into the bucket from UDF_BUNDLE_GCS_URI environment variable.

npm run udf:deploy