Skip to content

Commit

Permalink
Merge pull request #327 from navinrathore/ZinggPackage
Browse files Browse the repository at this point in the history
Python API - Specialized Pipes for SnowFlake, BigQuery etc.
  • Loading branch information
sonalgoyal authored Jun 14, 2022
2 parents b2e71b7 + 43d01fa commit 3e69376
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 10 deletions.
2 changes: 1 addition & 1 deletion assembly/src/assembly/dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/api</directory>
<outputDirectory>api</outputDirectory>
<outputDirectory>scala</outputDirectory>
<includes>
<include>**/*</include>
</includes>
Expand Down
File renamed without changes.
Empty file added python/api/__init__.py
Empty file.
17 changes: 11 additions & 6 deletions api/python/zingg.py → python/api/zingg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ def getArgs(self):
def setArgs(self, argumentsObj):
self.args = argumentsObj

def setData(self, pipe):
dataPipe = gateway.new_array(jvm.zingg.client.pipe.Pipe, 1)
dataPipe[0] = pipe.getPipe()
def setData(self, *pipes):
dataPipe = gateway.new_array(jvm.zingg.client.pipe.Pipe, len(pipes))
for idx, pipe in enumerate(pipes):
dataPipe[idx] = pipe.getPipe()
self.args.setData(dataPipe)

def setOutput(self, pipe):
outputPipe = gateway.new_array(jvm.zingg.client.pipe.Pipe, 1)
outputPipe[0] = pipe.getPipe()
def setOutput(self, *pipes):
outputPipe = gateway.new_array(jvm.zingg.client.pipe.Pipe, len(pipes))
for idx, pipe in enumerate(pipes):
outputPipe[idx] = pipe.getPipe()
self.args.setOutput(outputPipe)

def setModelId(self, id):
Expand Down Expand Up @@ -163,6 +165,9 @@ def addProperty(self, name, value):
def setSchema(self, s):
self.pipe.setSchema(s)

def toString(self):
return self.pipe.toString()

def parseArguments(argv):
parser = argparse.ArgumentParser(description='Zingg\'s python APIs')
mandatoryOptions = parser.add_argument_group('mandatory arguments')
Expand Down
56 changes: 56 additions & 0 deletions python/api/zinggPipes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import logging
from zingg import *
import pandas as pd

LOG = logging.getLogger("zingg.pipes")

Format = jvm.zingg.client.pipe.Format
FilePipe = jvm.zingg.client.pipe.FilePipe

class CsvPipe(Pipe):
def __init__(self, name):
Pipe.__init__(self, name, Format.CSV.type())
Pipe.addProperty(self, FilePipe.HEADER,"true")
def setDelimiter(self, delimiter):
Pipe.addProperty(self, "delimiter", delimiter)
def setLocation(self, location):
Pipe.addProperty(self, FilePipe.LOCATION, location)

class BigQueryPipe(Pipe):
def __init__(self,name):
Pipe.__init__(self, name, "bigquery")
Pipe.addProperty(self, "viewsEnabled", "true")
def setCredentialFile(self, file):
Pipe.addProperty(self, "credentialsFile", file)
def setTable(self, table):
Pipe.addProperty(self, "table", table)
def setTemporaryGcsBucket(self, bucket):
Pipe.addProperty(self, "temporaryGcsBucket", bucket)
def setViewsEnabled(self, isEnabled):
Pipe.addProperty(self, "viewsEnabled", isEnabled)

class SnowflakePipe(Pipe):
def __init__(self,name):
Pipe.__init__(self, name, Format.SNOWFLAKE.type())
def setURL(self, url):
Pipe.addProperty(self, "sfUrl", url)
def setUser(self, user):
Pipe.addProperty(self, "sfUser", user)
def setPassword(self, passwd):
Pipe.addProperty(self, "sfPassword", passwd)
def setDatabase(self, db):
Pipe.addProperty(self, "sfDatabase", db)
def setSFSchema(self, schema):
Pipe.addProperty(self, "sfSchema", schema)
def setWarehouse(self, warehouse):
Pipe.addProperty(self, "sfWarehouse", warehouse)
def setDbTable(self, dbtable):
Pipe.addProperty(self, "dbtable", dbtable)

class InMemoryPipe(Pipe):
def __init__(self, name):
Pipe.__init__(self, name, Format.INMEMORY.type())
def setDataset(self, ds):
Pipe.getPipe(self).setDataset(ds)
def getDataset(self):
return Pipe.getPipe(self).getDataset()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from zingg import *
from python.api.zingg import *

#build the arguments for zingg
args = Arguments()
Expand Down
2 changes: 1 addition & 1 deletion python/phases/assessModel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from api.python.zingg import *
from python.api.zingg import *
import pandas as pd
import seaborn as sn
import matplotlib.pyplot as plt
Expand Down
2 changes: 1 addition & 1 deletion python/phases/exportModel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from api.python.zingg import *
from python.api.zingg import *
import sys
import argparse
import os
Expand Down
File renamed without changes.

0 comments on commit 3e69376

Please sign in to comment.