Java Code Examples for org.apache.calcite.avatica.util.Cursor#Accessor
The following examples show how to use
org.apache.calcite.avatica.util.Cursor#Accessor .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AvaticaResultSet.java From calcite-avatica with Apache License 2.0 | 5 votes |
/** * Returns the accessor for column with a given index. * * @param columnIndex 1-based column index * @return Accessor * @throws SQLException if index is not valid */ private Cursor.Accessor getAccessor(int columnIndex) throws SQLException { checkOpen(); try { return accessorList.get(columnIndex - 1); } catch (IndexOutOfBoundsException e) { throw AvaticaConnection.HELPER.createException( "invalid column ordinal: " + columnIndex); } }
Example 2
Source File: DremioResultSetImpl.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public Object getObject( int columnIndex ) throws SQLException { throwIfClosed(); final Cursor.Accessor accessor; try { accessor = accessorList.get(columnIndex - 1); } catch (IndexOutOfBoundsException e) { throw new SQLException("invalid column ordinal: " + columnIndex); } final ColumnMetaData metaData = columnMetaDataList.get(columnIndex - 1); // Dremio returns a float (4bytes) for a SQL Float whereas Calcite would return a double (8bytes) int typeId = (metaData.type.id != Types.FLOAT) ? metaData.type.id : Types.REAL; return AvaticaSite.get(accessor, typeId, localCalendar); }
Example 3
Source File: AvaticaResultSet.java From calcite-avatica with Apache License 2.0 | 4 votes |
public Object getObject(int columnIndex) throws SQLException { final Cursor.Accessor accessor = getAccessor(columnIndex); final ColumnMetaData metaData = columnMetaDataList.get(columnIndex - 1); return AvaticaSite.get(accessor, metaData.type.id, localCalendar); }
Example 4
Source File: AvaticaSite.java From calcite-avatica with Apache License 2.0 | 4 votes |
/** Similar logic to {@link #setObject}. */ public static Object get(Cursor.Accessor accessor, int targetSqlType, Calendar localCalendar) throws SQLException { switch (targetSqlType) { case Types.CLOB: case Types.DATALINK: case Types.NCLOB: case Types.REF: case Types.SQLXML: throw notImplemented(); case Types.STRUCT: return accessor.getStruct(); case Types.ARRAY: return accessor.getArray(); case Types.BIGINT: final long aLong = accessor.getLong(); if (aLong == 0 && accessor.wasNull()) { return null; } return aLong; case Types.BINARY: case Types.LONGVARBINARY: case Types.VARBINARY: return accessor.getBytes(); case Types.BIT: case Types.BOOLEAN: final boolean aBoolean = accessor.getBoolean(); if (!aBoolean && accessor.wasNull()) { return null; } return aBoolean; case Types.BLOB: return accessor.getBlob(); case Types.DATE: return accessor.getDate(localCalendar); case Types.DECIMAL: case Types.NUMERIC: return accessor.getBigDecimal(); case Types.DISTINCT: throw notImplemented(); case Types.DOUBLE: case Types.FLOAT: // yes really; SQL FLOAT is up to 8 bytes final double aDouble = accessor.getDouble(); if (aDouble == 0 && accessor.wasNull()) { return null; } return aDouble; case Types.INTEGER: final int anInt = accessor.getInt(); if (anInt == 0 && accessor.wasNull()) { return null; } return anInt; case Types.JAVA_OBJECT: case Types.OTHER: return accessor.getObject(); case Types.LONGNVARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.VARCHAR: case Types.CHAR: case Types.NCHAR: return accessor.getString(); case Types.REAL: final float aFloat = accessor.getFloat(); if (aFloat == 0 && accessor.wasNull()) { return null; } return aFloat; case Types.ROWID: throw notImplemented(); case Types.SMALLINT: final short aShort = accessor.getShort(); if (aShort == 0 && accessor.wasNull()) { return null; } return aShort; case Types.TIME: return accessor.getTime(localCalendar); case Types.TIMESTAMP: return accessor.getTimestamp(localCalendar); case Types.TINYINT: final byte aByte = accessor.getByte(); if (aByte == 0 && accessor.wasNull()) { return null; } return aByte; default: throw notImplemented(); } }
Example 5
Source File: AvaticaResultSet.java From calcite-avatica with Apache License 2.0 | 2 votes |
/** * Returns the accessor for column with a given label. * * @param columnLabel Column label * @return Accessor * @throws SQLException if there is no column with that label */ private Cursor.Accessor getAccessor(String columnLabel) throws SQLException { checkOpen(); return accessorList.get(findColumn0(columnLabel)); }