kishoreg commented on a change in pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#discussion_r445753458



##########
File path: 
pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java
##########
@@ -0,0 +1,1317 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLType;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.codec.binary.Hex;
+
+
+public class PinotResultSet implements ResultSet {

Review comment:
       can we create AbstractBaseResultSet and implement all unsupported 
exceptions in that class. this will improve readability in this class

##########
File path: 
pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java
##########
@@ -0,0 +1,1317 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLType;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.commons.codec.binary.Hex;
+
+
+public class PinotResultSet implements ResultSet {
+  public static final String TIMESTAMP_FORMAT = "dd-mm-yyyy HH:MM:SS";
+  public static final String DATE_FORMAT = "dd-mm-yyyy";
+  private org.apache.pinot.client.ResultSet _resultSet;
+  private int _totalRows;
+  private int _currentRow;
+  private Map<String, Integer> _columns = new HashMap<>();
+
+  public PinotResultSet(org.apache.pinot.client.ResultSet resultSet) {
+    _resultSet = resultSet;
+    _totalRows = _resultSet.getRowCount();
+    _currentRow = -1;
+    for (int i = 0; i < _resultSet.getColumnCount(); i++) {
+      _columns.put(_resultSet.getColumnName(i), i);
+    }
+  }
+
+  @Override
+  public boolean absolute(int row)
+      throws SQLException {
+    if (row >= 0 && row < _totalRows) {
+      _currentRow = row;
+      return true;
+    } else if (row < 0 && Math.abs(row) <= _totalRows) {
+      _currentRow = _totalRows + row;
+      return true;
+    }
+
+    return false;
+  }
+
+  @Override
+  public void afterLast()
+      throws SQLException {
+    _currentRow = _totalRows;
+  }
+
+  @Override
+  public void beforeFirst()
+      throws SQLException {
+    _currentRow = -1;
+  }
+
+  @Override
+  public void cancelRowUpdates()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public void clearWarnings()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public void close()
+      throws SQLException {
+      _resultSet = null;
+      _totalRows = 0;
+      _currentRow = -1;
+      _columns.clear();;
+  }
+
+  @Override
+  public void deleteRow()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public int findColumn(String columnLabel)
+      throws SQLException {
+    if (_columns.containsKey(columnLabel)) {
+      return _columns.get(columnLabel);
+    } else {
+      throw new SQLException("Column with label {} not found in ResultSet", 
columnLabel);
+    }
+  }
+
+  @Override
+  public boolean first()
+      throws SQLException {
+    _currentRow = 0;
+    return true;
+  }
+
+  @Override
+  public Array getArray(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Array getArray(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public InputStream getAsciiStream(int columnIndex)
+      throws SQLException {
+    String value = getString(columnIndex);
+    InputStream in = new 
ByteArrayInputStream(value.getBytes(StandardCharsets.US_ASCII));
+    return in;
+  }
+
+  @Override
+  public InputStream getAsciiStream(String columnLabel)
+      throws SQLException {
+    return getAsciiStream(findColumn(columnLabel));
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex)
+      throws SQLException {
+    return getBigDecimal(columnIndex, 0);
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnLabel)
+      throws SQLException {
+    return getBigDecimal(findColumn(columnLabel));
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(int columnIndex, int scale)
+      throws SQLException {
+    try {
+      String value = getString(columnIndex);
+      BigDecimal bigDecimal = new BigDecimal(value).setScale(scale);
+      return bigDecimal;
+    }catch (Exception e){
+      throw new SQLException("Unable to fetch BigDecimal value", e);
+    }
+  }
+
+  @Override
+  public BigDecimal getBigDecimal(String columnLabel, int scale)
+      throws SQLException {
+    return getBigDecimal(findColumn(columnLabel), scale);
+  }
+
+  @Override
+  public InputStream getBinaryStream(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public InputStream getBinaryStream(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Blob getBlob(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Blob getBlob(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public boolean getBoolean(int columnIndex)
+      throws SQLException {
+    return Boolean.parseBoolean(_resultSet.getString(_currentRow, 
columnIndex));
+  }
+
+  @Override
+  public boolean getBoolean(String columnLabel)
+      throws SQLException {
+    return getBoolean(findColumn(columnLabel));
+  }
+
+  @Override
+  public byte getByte(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public byte getByte(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public byte[] getBytes(int columnIndex)
+      throws SQLException {
+    try {
+      String value = _resultSet.getString(_currentRow, columnIndex);
+      return Hex.decodeHex(value.toCharArray());
+    } catch (Exception e) {
+      throw new SQLException(String.format("Unable to fetch value for column 
%d", columnIndex), e);
+    }
+  }
+
+  @Override
+  public byte[] getBytes(String columnLabel)
+      throws SQLException {
+    return getBytes(findColumn(columnLabel));
+  }
+
+  @Override
+  public Reader getCharacterStream(int columnIndex)
+      throws SQLException {
+    InputStream in = getUnicodeStream(columnIndex);
+    Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8);
+    return reader;
+  }
+
+  @Override
+  public Reader getCharacterStream(String columnLabel)
+      throws SQLException {
+    return getCharacterStream(findColumn(columnLabel));
+  }
+
+  @Override
+  public Clob getClob(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Clob getClob(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public int getConcurrency()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public String getCursorName()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Date getDate(int columnIndex)
+      throws SQLException {
+    return getDate(columnIndex, Calendar.getInstance());
+  }
+
+  @Override
+  public Date getDate(String columnLabel)
+      throws SQLException {
+    return getDate(findColumn(columnLabel), Calendar.getInstance());
+  }
+
+  @Override
+  public Date getDate(int columnIndex, Calendar cal)
+      throws SQLException {
+    try {
+      String value = getString(columnIndex);
+      SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+      java.util.Date date = dateFormat.parse(value);
+      cal.setTime(date);
+      Date sqlDate = new Date(cal.getTimeInMillis());
+      return sqlDate;
+    } catch (Exception e) {
+      throw new SQLException("Unable to fetch date", e);
+    }
+  }
+
+  @Override
+  public Date getDate(String columnLabel, Calendar cal)
+      throws SQLException {
+    return getDate(findColumn(columnLabel), cal);
+  }
+
+  @Override
+  public double getDouble(int columnIndex)
+      throws SQLException {
+    return _resultSet.getDouble(_currentRow, columnIndex);
+  }
+
+  @Override
+  public double getDouble(String columnLabel)
+      throws SQLException {
+    return getDouble(findColumn(columnLabel));
+  }
+
+  @Override
+  public int getFetchDirection()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public void setFetchDirection(int direction)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public int getFetchSize()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public void setFetchSize(int rows)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public float getFloat(int columnIndex)
+      throws SQLException {
+    return _resultSet.getFloat(_currentRow, columnIndex);
+  }
+
+  @Override
+  public float getFloat(String columnLabel)
+      throws SQLException {
+    return getFloat(findColumn(columnLabel));
+  }
+
+  @Override
+  public int getHoldability()
+      throws SQLException {
+    return 0;
+  }
+
+  @Override
+  public int getInt(int columnIndex)
+      throws SQLException {
+    return _resultSet.getInt(_currentRow, columnIndex);
+  }
+
+  @Override
+  public int getInt(String columnLabel)
+      throws SQLException {
+    return getInt(findColumn(columnLabel));
+  }
+
+  @Override
+  public long getLong(int columnIndex)
+      throws SQLException {
+    return _resultSet.getLong(_currentRow, columnIndex);
+  }
+
+  @Override
+  public long getLong(String columnLabel)
+      throws SQLException {
+    return getLong(findColumn(columnLabel));
+  }
+
+  @Override
+  public ResultSetMetaData getMetaData()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Reader getNCharacterStream(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Reader getNCharacterStream(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public NClob getNClob(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public NClob getNClob(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public String getNString(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public String getNString(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Object getObject(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Object getObject(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Object getObject(int columnIndex, Map<String, Class<?>> map)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Object getObject(String columnLabel, Map<String, Class<?>> map)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public <T> T getObject(int columnIndex, Class<T> type)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public <T> T getObject(String columnLabel, Class<T> type)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Ref getRef(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public Ref getRef(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public int getRow()
+      throws SQLException {
+    return _currentRow;
+  }
+
+  @Override
+  public RowId getRowId(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public RowId getRowId(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public SQLXML getSQLXML(int columnIndex)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public SQLXML getSQLXML(String columnLabel)
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public short getShort(String columnLabel)
+      throws SQLException {
+    return getShort(columnLabel);
+  }
+
+  @Override
+  public short getShort(int columnIndex)
+      throws SQLException {
+    Integer value = getInt(columnIndex);
+    return value.shortValue();
+  }
+
+  @Override
+  public Statement getStatement()
+      throws SQLException {
+    throw new SQLFeatureNotSupportedException();
+  }
+
+  @Override
+  public String getString(int columnIndex)
+      throws SQLException {
+    return _resultSet.getString(_currentRow, columnIndex);
+  }
+
+  @Override
+  public String getString(String columnLabel)
+      throws SQLException {
+    return getString(findColumn(columnLabel));
+  }
+
+  @Override
+  public Time getTime(int columnIndex)
+      throws SQLException {
+    return getTime(columnIndex, Calendar.getInstance());
+  }
+
+  @Override
+  public Time getTime(String columnLabel)
+      throws SQLException {
+    return getTime(findColumn(columnLabel), Calendar.getInstance());
+  }
+
+  @Override
+  public Time getTime(int columnIndex, Calendar cal)
+      throws SQLException {
+    try {
+      String value = getString(columnIndex);
+      SimpleDateFormat dateFormat = new SimpleDateFormat(TIMESTAMP_FORMAT);

Review comment:
       better to cache this 

##########
File path: 
pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotDriver.java
##########
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.client;
+
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Logger;
+import org.apache.pinot.client.utils.DriverUtils;
+import org.slf4j.LoggerFactory;
+
+
+public class PinotDriver implements Driver {
+  private static final org.slf4j.Logger LOGGER = 
LoggerFactory.getLogger(PinotDriver.class);
+  private final String SCHEME = "pinot";
+
+  @Override
+  public Connection connect(String url, Properties info)
+      throws SQLException {
+    try {
+      PinotClientTransport pinotClientTransport = new 
JsonAsyncHttpPinotClientTransportFactory().buildTransport();
+      List<String> brokerList = DriverUtils.getBrokersFromURL(url);
+      return new PinotConnection(brokerList, pinotClientTransport);
+    } catch (Exception e) {
+      LOGGER.error("Failed to connect to url : {}", url, e);
+      throw new SQLException("Failed to connect to url : {}", url, e);
+    }
+  }
+
+  @Override
+  public boolean acceptsURL(String url)
+      throws SQLException {
+    String cleanURI = url.substring(5);
+    URI uri = URI.create(cleanURI);
+    return uri.getScheme().contentEquals(SCHEME);
+  }
+
+  @Override
+  public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
+      throws SQLException {
+    return new DriverPropertyInfo[0];
+  }
+
+  @Override
+  public int getMajorVersion() {

Review comment:
       what should this return according to the spec

##########
File path: 
pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java
##########
@@ -0,0 +1,1227 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.client;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.sql.Array;
+import java.sql.Blob;
+import java.sql.Clob;
+import java.sql.Date;
+import java.sql.NClob;
+import java.sql.Ref;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.RowId;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLWarning;
+import java.sql.SQLXML;
+import java.sql.Statement;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class PinotResultSet implements ResultSet {
+  private final org.apache.pinot.client.ResultSet _resultSet;
+  private int _totalRows;
+  private int _currentRow;
+  private Map<String, Integer> _columns = new HashMap<>();
+
+  public PinotResultSet(org.apache.pinot.client.ResultSet resultSet) {

Review comment:
       +1, lets use resultTable. Its ok to say we support jdbc only on SQL 
endpoint




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to