Giter Site home page Giter Site logo

pyspark-cdm's Introduction

PySpark Common Data Model

A Python library for working with the Common Data Model (CDM) using PySpark.

Usage

Manifest

When using a manifest based CDM export you can use the following code to load the data:

from pyspark_cdm import Manifest
from cdm.objectmodel import CdmCorpusDefinition
from cdm.storage import LocalAdapter

# Create a corpus definition.
corpus = CdmCorpusDefinition()

# Point to the root of your cdm export.
corpus.storage.mount("local", LocalAdapter(root="/dbfs/mnt/cdm/"))

# Create the manifest, and point to your entry manifest.
manifest = Manifest(corpus=corpus, path="local:/Tables/Tables.manifest.cdm.json")

# You can now inspect all the entities.
print([entity.name for entity in manifest.entities])

Model

The package also works with the older model cdm export:

from pyspark_cdm import Manifest
from cdm.objectmodel import CdmCorpusDefinition
from cdm.storage import LocalAdapter
from cdm.storage.adls import ADLSAdapter

# Create a corpus definition.
corpus = CdmCorpusDefinition()

# Point to the root of your cdm export.
corpus.storage.mount('local', LocalAdapter(root="/dbfs/mnt/cdm/"))

# If your export contains adls paths, you need to define an adls adapter.
corpus.storage.mount('adls', ADLSAdapter(
    root='/<container_name>',
    hostname='<endpoint>.dfs.core.windows.net',
    tenant='72f988bf-86f1-41af-91ab-2d7cd011db47',
    resource='https://storage.azure.com',
))

# Create the manifest, and point to your model json file.
manifest = Manifest(corpus=corpus, path="local:/model.json")

# You can now inspect all the entities.
print([entity.name for entity in manifest.entities])

Loading data

You can load data from the entities themselves.

# Load the dataframe.
df = entity.get_dataframe(spark)

# Print the number of rows.
print(df.count())

Setup

MacOs

  1. Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install Java
brew install adoptopenjdk

pyspark-cdm's People

Contributors

juleshuisman avatar paulorijnberg avatar

Watchers

 avatar  avatar

pyspark-cdm's Issues

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.