reformatted PipeUtil - #1183
Conversation
|
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 |
Sonal (sonalgoyal)
left a comment
There was a problem hiding this comment.
i took a high level look and added my comments.
|
|
||
| //spark session | ||
| //dataset | ||
| public interface PipeUtilBase<S, D, R, C> { |
There was a problem hiding this comment.
shouldnt this implement IPipeReader and IPipeWriter ?
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
i dont think we are doing anything jdbc stuff here. just call this DefaultWriterStrategy
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
this will break - for snowflake and other out of the box formats we currently support
There was a problem hiding this comment.
mongo, elastic etc will break too
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
this is not filereadstrategy. we need a default strategy which has reader.load which is called in the other circumstances
There was a problem hiding this comment.
Changed to Default read strategy
| if (Pipe.FORMAT_INMEMORY.equals(pipe.getFormat())) { | ||
| return new InMemoryReadStrategy<>(); | ||
| } else { | ||
| return new FileReadStrategy<>(); |
There was a problem hiding this comment.
add defaultstrategy here
There was a problem hiding this comment.
added default strategy instead of file read strategy
| import zingg.common.client.ZFrame; | ||
| import zingg.common.client.ZinggClientException; | ||
|
|
||
| public interface DFReader<D, R, C> { |
There was a problem hiding this comment.
apply this naming convention consistently
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
common code across Helper, writers etc.
There was a problem hiding this comment.
Common helper is present for respective readers and writers
|
|
||
| DFReader<D,R,C> setSchema(String s); | ||
|
|
||
| ZFrame<D,R,C> load() throws ZinggClientException; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
we should abstract away these three calls and make it easier to read using a single method call.
There was a problem hiding this comment.
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())) { |
There was a problem hiding this comment.
inmem is no longer part of oss, please remove
There was a problem hiding this comment.
removed in-memory pipe
* 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>
No description provided.