Coder Social home page Coder Social logo

Store functions in YAML file about intake-spark HOT 2 CLOSED

intake avatar intake commented on August 25, 2024
Store functions in YAML file

from intake-spark.

Comments (2)

martindurant avatar martindurant commented on August 25, 2024

The reason behind this, is to prevent the execution of arbitrary code upon loading a catalog. I don't know how you could include actual serialised functions in YAML and load safely. You could, however, include strings to code that lives in modules, like "package.module.function", and it would be reasonable for intake-spark to acquire the ability to parse these at run-time. Intake already does something similar for dereferencing driver classes.

(note that, as far as I know, spark-sql queries are truly equivalent to their functional counterparts except for user-defined functions)

from intake-spark.

jecolvin avatar jecolvin commented on August 25, 2024

After looking through the source files and reading up more on PyYAML, I've discovered the solution. Your YAML file could look something like this:

sources:
  spark_dataframe:
    args:
      args:
      - - read
      - - jdbc
        - - jbdc:blah/
          - "TBL"
        - column: TBL_KEY
          lowerBound: 0
          numPartitions: 4
          properties:
            password: pwd
            user: user
          upperBound: 11000000
      - - withColumn
        - - foo
          - !!python/object/apply:pyspark.sql.functions.lit [1]
    description: ''
    driver: intake_spark.spark_sources.SparkDataFrame
    metadata: {}

You have to put the list with the function args in the same line using the square bracket syntax.

A decent amount of our queries look like sdf.groupby("foo").pivot("bar").agg([F.sum("col1"), F.countDistinct("col2")]) as we're having to create various higher-level groupings from the original data and then pivot off of that to create features.

Also now that I know this capability is possible I'll probably look into saving more complex transforms as custom functions bundled with our catalog that get called (for example for our utilization dataset I get the range of years the user is requesting and run a for loop to pivot out certain features by year, as typically our data scientists are using one year's utilization features to predict some utilization-based label for the next year).

from intake-spark.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.