Skip to content

reformatted PipeUtil - #1183

Merged
Sonal (sonalgoyal) merged 22 commits into
zinggAI:mainfrom
Nitish1814:pipeutil-refactor
Sep 2, 2025
Merged

reformatted PipeUtil#1183
Sonal (sonalgoyal) merged 22 commits into
zinggAI:mainfrom
Nitish1814:pipeutil-refactor

Conversation

@Nitish1814

Copy link
Copy Markdown
Contributor

No description provided.

@sania-16

Sania Goyal (sania-16) commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

these changes are from uc branch - we have already made basic level changes? Nitish (@Nitish1814)

@Nitish1814

Copy link
Copy Markdown
Contributor Author

these changes are from uc branch - we have already made basic level changes? Nitish (@Nitish1814)

These are completely new changes. whatever basic changes were made for UC this will override them

@sonalgoyal Sonal (sonalgoyal) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i took a high level look and added my comments.


//spark session
//dataset
public interface PipeUtilBase<S, D, R, C> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to IPipeUtil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt this implement IPipeReader and IPipeWriter ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public interface PipeUtilBase<S, D, R, C> extends IPipeUtilReader<D, R, C>, IPipeUtilWriter<D, R, C>

import zingg.common.client.util.DFWriter;
import zingg.common.client.util.writer.WriterStrategy;

public class JdbcWriterStrategy<D, R, C> implements WriterStrategy<D, R, C> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we are doing anything jdbc stuff here. just call this DefaultWriterStrategy

@Nitish1814 Nitish (Nitish1814) Aug 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, so it will be DefaultWriterStrategy which will support some out of the box formats like Snowflake etc

this.dfWriter = dfWriter;
}

public WriterStrategy<D, R, C> getStrategy(Pipe<D, R, C> pipe) throws NoSuchObjectException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break - for snowflake and other out of the box formats we currently support

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mongo, elastic etc will break too

@Nitish1814 Nitish (Nitish1814) Aug 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, so it will be DefaultWriterStrategy which will support some out of the box formats like Snowflake etc

if (pipe.getProps().containsKey(FilePipe.LOCATION)) {
return reader.load(pipe.get(FilePipe.LOCATION));
} else {
return reader.load();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not filereadstrategy. we need a default strategy which has reader.load which is called in the other circumstances

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to Default read strategy

if (Pipe.FORMAT_INMEMORY.equals(pipe.getFormat())) {
return new InMemoryReadStrategy<>();
} else {
return new FileReadStrategy<>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add defaultstrategy here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added default strategy instead of file read strategy

import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;

public interface DFReader<D, R, C> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

start name with I

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply this naming convention consistently

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been changed

public void write(ZFrame<D, R, C> frame, Pipe<D, R, C> pipe) throws Exception {
DFWriter<D, R, C> writer = dfWriter
.format(pipe.getFormat());
writer.setMode(pipe.getMode() != null ? pipe.getMode() : "Append");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

common code across Helper, writers etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common helper is present for respective readers and writers


DFReader<D,R,C> setSchema(String s);

ZFrame<D,R,C> load() throws ZinggClientException;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all DFReaders do not support load(). For example the filebased ones dont. We need a base interface with format and option, common to both reader and writer. Define DFReader load which takes the pipe

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a generic facade over DataFrameReader from spark and Snowflake


public class Helper {

public static <D, R, C> IDFReader<D, R, C> initializeReaderForPipe(Pipe<D, R, C> pipe, IDFReader<D, R, C> dFReader) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a default method in the IDFReader instead of having it separately. Or we can have an abstract class extending IDFReader and define it there. Helpers and Utils should typically be buitl for cross cutting concerns, which this is not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally there should be a super interface with format, setSchema and option which can be inherited by both IDFReader and IDFWriter.

protected ZFrame<D, R, C> readSinglePipe(Pipe<D, R, C> pipe, boolean addSource) throws ZinggClientException {
try {
LOG.warn("Reading " + pipe);
IDFReader<D, R, C> reader = Helper.initializeReaderForPipe(pipe, getReader());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should abstract away these three calls and make it easier to read using a single method call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstracted


public class ReadStrategyFactory<D, R, C> {
public ReadStrategy<D, R, C> getStrategy(Pipe<D, R, C> pipe) {
if (Pipe.FORMAT_INMEMORY.equals(pipe.getFormat())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inmem is no longer part of oss, please remove

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed in-memory pipe

@sonalgoyal
Sonal (sonalgoyal) merged commit bf33525 into zinggAI:main Sep 2, 2025
1 check passed
Nitish (Nitish1814) added a commit to Nitish1814/zingg-Nitish that referenced this pull request Sep 4, 2025
* reformatted PipeUtil

* break reader and  writer as two separate components

* changes

* changed variable scope

* added Helper class for initializing reader

* updated WriterStrategyFactory

* updated PipeUtilBase

* renamed interfaces names and added Helper to for initializing writer

* removed loader with string

* added default reader and writer strategy

* removed inMemory read strategy

* changed location to path property

* removed in-memory pipes

* made variable protected

* updated strategy reader

* added back compatibility for location

* removed helper from reader and writer

* added pipe to writer strategy

* updated snowflake format

* reverted back snowflake format

* added constant location and path

---------

Co-authored-by: Nitish <nitish.joshi1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants