This is an automated email from the ASF dual-hosted git repository. kharekartik pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push: new 024dfc2 Return datatypes along with column names (#5946) 024dfc2 is described below commit 024dfc2082538bfd38cc7686aeb95b404baefdec Author: Kartik Khare <kharekar...@gmail.com> AuthorDate: Tue Sep 8 12:07:12 2020 +0530 Return datatypes along with column names (#5946) * Return datatypes along with column names * Add test for result data type * Fix style checks --- .../apache/pinot/client/PinotResultMetadata.java | 4 +- .../org/apache/pinot/client/PinotResultSet.java | 5 +- .../org/apache/pinot/client/utils/Constants.java | 18 ++++---- .../apache/pinot/client/PinotResultSetTest.java | 53 ++++++++++++++-------- .../src/test/resources/result_table.json | 48 ++++++++++++++++++++ 5 files changed, 95 insertions(+), 33 deletions(-) diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultMetadata.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultMetadata.java index 138292c..12a2d9e 100644 --- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultMetadata.java +++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultMetadata.java @@ -19,7 +19,6 @@ package org.apache.pinot.client; import java.sql.SQLException; -import java.sql.Types; import java.util.HashMap; import java.util.Map; import org.apache.pinot.client.base.AbstractBaseResultSetMetadata; @@ -31,8 +30,9 @@ public class PinotResultMetadata extends AbstractBaseResultSetMetadata { private Map<Integer, String> _columns = new HashMap<>(); private Map<Integer, String> _columnDataTypes = new HashMap<>(); - public PinotResultMetadata(int totalColumns, Map<String, Integer> columnsNameToIndex) { + public PinotResultMetadata(int totalColumns, Map<String, Integer> columnsNameToIndex, Map<Integer, String> columnDataTypes) { _totalColumns = totalColumns; + _columnDataTypes = columnDataTypes; for (Map.Entry<String, Integer> entry : columnsNameToIndex.entrySet()) { _columns.put(entry.getValue(), entry.getKey()); } diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java index 1f36044..cf3ddbc 100644 --- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java +++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotResultSet.java @@ -32,7 +32,6 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Time; import java.sql.Timestamp; -import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; import java.util.Map; @@ -51,6 +50,7 @@ public class PinotResultSet extends AbstractBaseResultSet { private int _currentRow; private int _totalColumns; private Map<String, Integer> _columns = new HashMap<>(); + private Map<Integer, String> _columnDataTypes = new HashMap<>(); private boolean _closed; private boolean _wasNull = false; @@ -62,6 +62,7 @@ public class PinotResultSet extends AbstractBaseResultSet { _closed = false; for (int i = 0; i < _totalColumns; i++) { _columns.put(_resultSet.getColumnName(i), i + 1); + _columnDataTypes.put(i + 1, _resultSet.getColumnDataType(i)); } } @@ -167,7 +168,7 @@ public class PinotResultSet extends AbstractBaseResultSet { public ResultSetMetaData getMetaData() throws SQLException { validateState(); - return new PinotResultMetadata(_totalColumns, _columns); + return new PinotResultMetadata(_totalColumns, _columns, _columnDataTypes); } @Override diff --git a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/Constants.java b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/Constants.java index b86a1d2..425bec9 100644 --- a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/Constants.java +++ b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/utils/Constants.java @@ -18,8 +18,6 @@ */ package org.apache.pinot.client.utils; - - public class Constants { public static final String DRIVER_NAME = "APACHE_PINOT_DRIVER"; public static final String DRIVER_VERSION = "1.0"; @@ -32,11 +30,15 @@ public class Constants { public static final String[] SCHEMA_COLUMNS = {"TABLE_SCHEM", "TABLE_CATALOG"}; public static final String[] SCHEMA_COLUMNS_DTYPES = {"STRING", "STRING"}; - public static final String[] TABLE_COLUMNS = {"TABLE_SCHEM", "TABLE_CATALOG", "TABLE_NAME", "TABLE_TYPE", "REMARKS", "TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION"}; - public static final String[] TABLE_COLUMNS_DTYPES = {"STRING", "STRING","STRING", "STRING","STRING", "STRING","STRING", "STRING","STRING"}; + public static final String[] TABLE_COLUMNS = + {"TABLE_SCHEM", "TABLE_CATALOG", "TABLE_NAME", "TABLE_TYPE", "REMARKS", "TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION"}; + public static final String[] TABLE_COLUMNS_DTYPES = + {"STRING", "STRING", "STRING", "STRING", "STRING", "STRING", "STRING", "STRING", "STRING", "STRING"}; - public static final String[] TABLE_SCHEMA_COLUMNS = {"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATALOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN"}; - public static final String[] TABLE_SCHEMA_COLUMNS_DTYPES = {"STRING", "STRING", "STRING", "STRING", "INT", "STRING", "INT", "INT", "INT", "INT", "INT", "STRING", "STRING", "INT", "INT", "INT","INT", "STRING", "STRING", "STRING", "STRING", "INT", "STRING", "STRING"}; + public static final String[] TABLE_SCHEMA_COLUMNS = + {"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATALOG", "SCOPE_SCHEMA", "SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATEDCOLUMN"}; + public static final String[] TABLE_SCHEMA_COLUMNS_DTYPES = + {"STRING", "STRING", "STRING", "STRING", "INT", "STRING", "INT", "INT", "INT", "INT", "INT", "STRING", "STRING", "INT", "INT", "INT", "INT", "STRING", "STRING", "STRING", "STRING", "INT", "STRING", "STRING"}; public static final String[] TABLE_TYPES_COLUMNS = {"TABLE_TYPE"}; public static final String[] TABLE_TYPES_COLUMNS_DTYPES = {"STRING"}; @@ -44,7 +46,6 @@ public class Constants { public static final String TABLE_TYPE = "TABLE"; public static final String GLOBAL_CATALOG = "global"; - public static final String SYS_FUNCTIONS = "maxTimeuuid,minTimeuuid,token,uuid"; public static final String NUM_FUNCTIONS = "avg,count,max,min,sum,exp,ln,ceil,floor,sqrt"; public static final String TIME_FUNCTIONS = @@ -54,6 +55,5 @@ public class Constants { + "fromEpochSecondsBucket,fromEpochMinutesBucket,fromEpochHoursBucket,fromEpochDaysBucket," + "toDateTime,fromDateTime,round,now"; public static final String STRING_FUNCTIONS = - "lower,upper,trim,ltrim,rtrim,subst,reverse,replace,lpad,rpad,length,strpos,startsWith,concat"; - + "lower,upper,trim,ltrim,rtrim,subst,reverse,replace,lpad,rpad,length,strpos,startsWith,concat"; } diff --git a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotResultSetTest.java b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotResultSetTest.java index a860818..e1b470b 100644 --- a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotResultSetTest.java +++ b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotResultSetTest.java @@ -20,7 +20,7 @@ package org.apache.pinot.client; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.InputStream; -import java.text.SimpleDateFormat; +import java.sql.ResultSetMetaData; import java.util.Calendar; import java.util.Date; import java.util.concurrent.Future; @@ -37,8 +37,7 @@ import org.testng.annotations.Test; * */ public class PinotResultSetTest { - public static final String TEST_RESULT_SET_RESOURCE = "selection.json"; - public static final String DATE_FORMAT = "yyyy-mm-dd"; + public static final String TEST_RESULT_SET_RESOURCE = "result_table.json"; private DummyJsonTransport _dummyJsonTransport = new DummyJsonTransport(); private PinotClientTransportFactory _previousTransportFactory = null; @@ -52,9 +51,10 @@ public class PinotResultSetTest { int currentRow = 0; while (pinotResultSet.next()) { Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(currentRow, 0)); - Assert.assertEquals(pinotResultSet.getLong(1), resultSet.getLong(currentRow, 0)); - Assert.assertEquals(pinotResultSet.getString(1), resultSet.getString(currentRow, 0)); - Assert.assertEquals(pinotResultSet.getDouble(79), resultSet.getDouble(currentRow, 78)); + Assert.assertEquals(pinotResultSet.getLong(2), resultSet.getLong(currentRow, 1)); + Assert.assertEquals(pinotResultSet.getFloat(3), resultSet.getFloat(currentRow, 2)); + Assert.assertEquals(pinotResultSet.getDouble(4), resultSet.getDouble(currentRow, 3)); + Assert.assertEquals(pinotResultSet.getString(5), resultSet.getString(currentRow, 4)); currentRow++; } } @@ -67,23 +67,23 @@ public class PinotResultSetTest { PinotResultSet pinotResultSet = new PinotResultSet(resultSet); int currentRow = 0; - int targetRow = 10; + int targetRow = 7; while (pinotResultSet.next() && currentRow < targetRow) { currentRow++; } - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(targetRow, 9)); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(targetRow, 0)); pinotResultSet.first(); Assert.assertTrue(pinotResultSet.isFirst()); - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(0, 9)); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(0, 0)); pinotResultSet.last(); Assert.assertTrue(pinotResultSet.isLast()); - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(resultSet.getRowCount() - 1, 9)); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(resultSet.getRowCount() - 1, 0)); pinotResultSet.previous(); - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(resultSet.getRowCount() - 2, 9)); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(resultSet.getRowCount() - 2, 0)); pinotResultSet.first(); pinotResultSet.previous(); @@ -94,14 +94,14 @@ public class PinotResultSetTest { Assert.assertTrue(pinotResultSet.isAfterLast()); pinotResultSet.first(); - pinotResultSet.absolute(18); - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(18, 9)); + pinotResultSet.absolute(7); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(7, 0)); pinotResultSet.relative(-5); - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(13, 9)); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(2, 0)); pinotResultSet.relative(1); - Assert.assertEquals(pinotResultSet.getInt(10), resultSet.getInt(14, 9)); + Assert.assertEquals(pinotResultSet.getInt(1), resultSet.getInt(3, 0)); } @Test @@ -114,9 +114,9 @@ public class PinotResultSetTest { int currentRow = 0; while (pinotResultSet.next()) { - Assert.assertEquals(IOUtils.toString(pinotResultSet.getAsciiStream(30)), resultSet.getString(currentRow, 29)); - Assert.assertEquals(IOUtils.toString(pinotResultSet.getUnicodeStream(30)), resultSet.getString(currentRow, 29)); - Assert.assertEquals(IOUtils.toString(pinotResultSet.getCharacterStream(30)), resultSet.getString(currentRow, 29)); + Assert.assertEquals(IOUtils.toString(pinotResultSet.getAsciiStream(5)), resultSet.getString(currentRow, 4)); + Assert.assertEquals(IOUtils.toString(pinotResultSet.getUnicodeStream(5)), resultSet.getString(currentRow, 4)); + Assert.assertEquals(IOUtils.toString(pinotResultSet.getCharacterStream(5)), resultSet.getString(currentRow, 4)); currentRow++; } } @@ -130,9 +130,9 @@ public class PinotResultSetTest { int currentRow = 0; while (pinotResultSet.next()) { - Date date = DateTimeUtils.getDateFromString(resultSet.getString(currentRow, 51), Calendar.getInstance()); + Date date = DateTimeUtils.getDateFromString(resultSet.getString(currentRow, 5), Calendar.getInstance()); long expectedTimeMillis = date.getTime(); - Assert.assertEquals(pinotResultSet.getDate(52).getTime(), expectedTimeMillis); + Assert.assertEquals(pinotResultSet.getDate(6).getTime(), expectedTimeMillis); currentRow++; } } @@ -149,6 +149,19 @@ public class PinotResultSetTest { } } + @Test + public void testGetResultMetadata() + throws Exception { + ResultSetGroup resultSetGroup = getResultSet(TEST_RESULT_SET_RESOURCE); + ResultSet resultSet = resultSetGroup.getResultSet(0); + PinotResultSet pinotResultSet = new PinotResultSet(resultSet); + ResultSetMetaData pinotResultSetMetadata = pinotResultSet.getMetaData(); + + for (int i = 0; i < resultSet.getColumnCount(); i++) { + Assert.assertEquals(pinotResultSetMetadata.getColumnTypeName(i + 1), resultSet.getColumnDataType(i)); + } + } + private ResultSetGroup getResultSet(String resourceName) { _dummyJsonTransport._resource = resourceName; Connection connection = ConnectionFactory.fromHostList("dummy"); diff --git a/pinot-clients/pinot-jdbc-client/src/test/resources/result_table.json b/pinot-clients/pinot-jdbc-client/src/test/resources/result_table.json new file mode 100644 index 0000000..f35b0fe --- /dev/null +++ b/pinot-clients/pinot-jdbc-client/src/test/resources/result_table.json @@ -0,0 +1,48 @@ +{ + "resultTable": { + "dataSchema": { + "columnNames": [ + "columnA", + "columnB", + "columnC", + "columnD", + "columnE", + "columnF" + ], + "columnDataTypes": [ + "INT", + "LONG", + "FLOAT", + "DOUBLE", + "STRING", + "STRING" + ] + }, + "rows": [ + [1,2324,3432.3443,2.2,"test", "2020-01-02"], + [2,2675,34323.342,3743724.1,"jbdasnfb", "2020-07-17"], + [3,854,4432.342,27834.2121,"JHBNNB", "2020-08-31"], + [4,74839,653.342,25452.5434432,"HHJkjkh", "1999-06-30"], + [5,567348213,5412.1,235235.23425,"ABCBD", "2004-06-29"], + [6,273924,54543.3453,6757.26775,"fuygad32748", "2018-02-13"], + [7,64383,265.534,345467.5667,"dyhudfa$%^&!#@^", "2014-11-04"], + [8,859348,54.98,87663.23456,"KHFGHJSF","2007-12-31"] + ] + }, + "exceptions": [], + "numServersQueried": 1, + "numServersResponded": 1, + "numSegmentsQueried": 1, + "numSegmentsProcessed": 1, + "numSegmentsMatched": 1, + "numConsumingSegmentsQueried": 0, + "numDocsScanned": 8, + "numEntriesScannedInFilter": 0, + "numEntriesScannedPostFilter": 250, + "numGroupsLimitReached": false, + "totalDocs": 97889, + "timeUsedMs": 5, + "segmentStatistics": [], + "traceInfo": {}, + "minConsumingFreshnessTimeMs": 0 +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org