You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/06/22 17:03:46 UTC

[GitHub] [incubator-pinot] KKcorps opened a new pull request #5602: Adding JDBC driver

KKcorps opened a new pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602


   ## Description
   * Initial code of JDBC driver 
   * Uses native java client to execute queries
   * A lot of methods are still not implemented. Many of them cannot be supported.
   
   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] kishoreg commented on pull request #5602: Adding support for JDBC

Posted by GitBox <gi...@apache.org>.
kishoreg commented on pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#issuecomment-653841814


   We can merge it. There are few things in parser that needs to be fixed. But independent of this PR. 


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #5602: Adding JDBC driver

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#discussion_r446639685



##########
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:
       It should return 1 only as per the spec. We can bump up the numbers in future releases of the driver.

##########
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:
       done




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #5602: Adding JDBC driver

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#discussion_r445821324



##########
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:
       Since I am using Java client to run queries, it is currently returning ResultSet.
   Should I create a seperate PR making changes in the Java client first so that it returns ResultTable?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #5602: Adding support for JDBC

Posted by GitBox <gi...@apache.org>.
kishoreg commented on a change in pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#discussion_r446675223



##########
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:
       sorry, my bad, ResultSet is still the right interface for the client. We need to deprecate few methods like 
   
   ```
     int getGroupKeyLength();
     String getGroupKeyColumnName(int groupKeyColumnIndex);
     int getGroupKeyInt(int rowIndex, int groupKeyColumnIndex);
     long getGroupKeyLong(int rowIndex, int groupKeyColumnIndex);
     float getGroupKeyFloat(int rowIndex, int groupKeyColumnIndex);
     double getGroupKeyDouble(int rowIndex, int groupKeyColumnIndex);
     String getGroupKeyString(int rowIndex, int groupKeyColumnIndex);
   ```
   
   jdbc driver code is not using any of them. so we are good here.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #5602: Adding JDBC driver

Posted by GitBox <gi...@apache.org>.
mayankshriv commented on a change in pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#discussion_r443757851



##########
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:
       Any reason why this has to use pinot.client.ResultSet (which seems like a really old class). We have ResultTable used for returning responses that is a more recent code, you may want to check it out.

##########
File path: pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java
##########
@@ -0,0 +1,41 @@
+/**
+ * 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.utils;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class DriverUtils {
+
+  public static List<String> getBrokersFromURL(String url) {
+    if (url.startsWith("jdbc:")) {

Review comment:
       Does it make sense to make it case insensitive check?

##########
File path: pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java
##########
@@ -0,0 +1,41 @@
+/**
+ * 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.utils;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class DriverUtils {

Review comment:
       Private constructor, if you don't want this class instantiated.

##########
File path: pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotStatement.java
##########
@@ -0,0 +1,309 @@
+/**
+ * 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.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.sql.SQLWarning;
+import java.sql.Statement;
+
+
+public class PinotStatement implements Statement {
+
+  private final org.apache.pinot.client.Connection _connection;
+  private final String _queryFormat;
+  private ResultSetGroup _resultSetGroup;
+
+  public PinotStatement(org.apache.pinot.client.Connection connection) {
+    _connection = connection;
+    _queryFormat = "sql";

Review comment:
       _queryFormat can be a static final, instead of initializing in constructor?

##########
File path: pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/DriverUtils.java
##########
@@ -0,0 +1,41 @@
+/**
+ * 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.utils;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class DriverUtils {
+
+  public static List<String> getBrokersFromURL(String url) {
+    if (url.startsWith("jdbc:")) {
+      url = url.substring(5);
+    }
+    URI uri = URI.create(url);
+    return getBrokersFromURI(uri);
+  }
+
+  public static List<String> getBrokersFromURI(URI uri) {
+    List<String> brokerList = new ArrayList<>();

Review comment:
       Use Collections.singletonList() instead?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] kishoreg merged pull request #5602: Adding support for JDBC

Posted by GitBox <gi...@apache.org>.
kishoreg merged pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602


   


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #5602: Adding JDBC driver

Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] mayankshriv commented on pull request #5602: Adding support for JDBC

Posted by GitBox <gi...@apache.org>.
mayankshriv commented on pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#issuecomment-653838757


   Anything remaining for this PR to be merged?


----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [incubator-pinot] KKcorps commented on a change in pull request #5602: Adding JDBC driver

Posted by GitBox <gi...@apache.org>.
KKcorps commented on a change in pull request #5602:
URL: https://github.com/apache/incubator-pinot/pull/5602#discussion_r446639708



##########
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:
       done




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org