-
Notifications
You must be signed in to change notification settings - Fork 29
@W-11168434 jdbc changes for Rainbow Connector #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
psasikaladevi
wants to merge
6
commits into
develop
Choose a base branch
from
W-11168434-jdbc-changes
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
442bbcd
Added support for Rainbow API
psasikaladevi 139a182
Fix for null pointer when the response is empty
psasikaladevi d8be071
Update RainbowDataStream.java
psasikaladevi 771defa
Added metadata support
psasikaladevi c717af3
Added Timestamp support and formatting
psasikaladevi bc5e450
Update ExtractArrowUtil.java
psasikaladevi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
src/main/java/com/salesforce/cdp/queryservice/core/RainbowQueryResultSet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| package com.salesforce.cdp.queryservice.core; | ||
|
|
||
| import com.google.protobuf.ListValue; | ||
| import com.google.protobuf.Value; | ||
| import com.salesforce.a360.queryservice.grpc.v1.AnsiSqlExtractQueryResponse; | ||
| import com.salesforce.a360.queryservice.grpc.v1.AnsiSqlQueryStreamResponse; | ||
| import com.salesforce.cdp.queryservice.util.ArrowUtil; | ||
| import com.salesforce.cdp.queryservice.util.RainbowDataStream; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import java.io.IOException; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| @Slf4j | ||
| public class RainbowQueryResultSet extends QueryServiceResultSet{ | ||
| List<Object> data ; | ||
| private RainbowDataStream dataStream; | ||
| private Iterator<AnsiSqlExtractQueryResponse> streamIterator; | ||
| private ArrowUtil arrowUtil; | ||
|
|
||
| public RainbowQueryResultSet(Iterator<AnsiSqlExtractQueryResponse> response, QueryServiceAbstractStatement statement) { | ||
| streamIterator = response; | ||
| arrowUtil = new ArrowUtil(); | ||
| dataStream = new RainbowDataStream(response); | ||
| initialiseArrowReader(); | ||
| this.statement = statement; | ||
| } | ||
|
|
||
| private void initialiseArrowReader() { | ||
| arrowUtil.createArrowReaderForStream(dataStream); | ||
| } | ||
| @Override | ||
| public boolean next() throws SQLException { | ||
| try { | ||
| errorOutIfClosed(); | ||
|
|
||
| if (currentRow == -1 && isNextChunkPresent()) { | ||
| getNextChunk(); | ||
| } else { | ||
| currentRow++; | ||
| } | ||
|
|
||
| if (currentRow < data.size()) { | ||
| return true; | ||
| } | ||
|
|
||
| if (isNextChunkPresent()) { | ||
| getNextChunk(); | ||
| if (data != null && data.size() > 0) { | ||
| return true; | ||
| } | ||
| } | ||
| arrowUtil.closeReader(); | ||
| closeDataStream(); | ||
| // Closing as this is move forward only cursor. | ||
| log.info("Resultset {} does not have any more rows. Total {} pages retrieved", this, currentPageNum); | ||
| return false; | ||
| } | ||
| catch (SQLException e){ | ||
|
|
||
| closeDataStream(); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| private void closeDataStream() { | ||
| if(dataStream != null) { | ||
| try { | ||
| dataStream.close(); | ||
| } | ||
| catch (IOException ex) { | ||
| ex.printStackTrace(); | ||
| } | ||
| dataStream = null; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Object getObject(int columnIndex) throws SQLException { | ||
| try{ | ||
| errorOutIfClosed(); | ||
| Object value = getValue(data.get(currentRow), columnIndex); | ||
| wasNull.set(value == null); | ||
| return value;} | ||
| catch(SQLException e) { | ||
| closeDataStream(); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Object getObject(String columnLabel) throws SQLException { | ||
| throw new SQLException("Not Implemented"); | ||
| } | ||
|
|
||
| @Override | ||
| protected Object getValue(Object row, String columnLabel) throws SQLException { | ||
| throw new SQLException("Not Implemented"); | ||
| } | ||
|
|
||
| private Object getValue(Object row, int columnIndex) throws SQLException { | ||
| return valueToObject(((ListValue) row).getValues(columnIndex)); | ||
| } | ||
|
|
||
| private static Object valueToObject(Value value) { | ||
| switch (value.getKindCase()) { | ||
| case NULL_VALUE: | ||
| return null; | ||
| case NUMBER_VALUE: | ||
| return value.getNumberValue(); | ||
| case STRING_VALUE: | ||
| return value.getStringValue(); | ||
| case BOOL_VALUE: | ||
| return value.getBoolValue(); | ||
| default: | ||
| throw new IllegalArgumentException(String.format("Unsupported protobuf value %s", value)); | ||
| } | ||
| } | ||
|
|
||
| private int getColumnIndexByName(String columnName) throws SQLException { | ||
| return ((QueryServiceResultSetMetaData)resultSetMetaData).getColumnNameToPosition().get(columnName); | ||
| } | ||
|
|
||
| private void getNextChunk() throws SQLException { | ||
| log.trace("Fetching page with number {} for resultset {}", ++currentPageNum, this); | ||
|
|
||
| try { | ||
| List<Object> rows = arrowUtil.getRowsFromRainbowResponse(); | ||
| if(rows != null && rows.size()>0){ | ||
| this.data = rows; | ||
| currentRow=0; | ||
| } | ||
| } catch (Exception e) { | ||
| log.error("Error while getting the data chunk {}", this, e); | ||
| closeDataStream(); | ||
| throw new SQLException(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected ResultSet getNextPageData() throws SQLException { | ||
| throw new SQLException("This method is not implemented"); | ||
| } | ||
|
|
||
| @Override | ||
| protected void updateState(ResultSet resultSet) throws SQLException { | ||
| throw new SQLException("This method is not implemented"); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isAfterLast() throws SQLException { | ||
| return !this.isNextChunkPresent() && this.currentRow >= this.data.size(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isLast() throws SQLException { | ||
| return !this.isNextChunkPresent() && this.currentRow == this.data.size() - 1; | ||
| } | ||
|
|
||
| private boolean isNextChunkPresent() throws SQLException { | ||
| try { | ||
| return streamIterator.hasNext(); | ||
| } catch (Exception e) { | ||
| throw new SQLException(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicate method, we should move it to util