@Override public long getLong(int field) { return delegate.getLong(field); }
@Override public long getLong(int field) { return delegate.getLong(field); }
@Override public long getLong(int field) { checkState(!closed); checkPositionIndex(field, types.size()); return currentCursor.getLong(field); }
@Override public long getLong(int field) { checkPositionIndex(field, delegateFieldCount + appendedTypes.size()); if (field < delegateFieldCount) { return delegate.getLong(field); } else { return (Long) appendedValues.get(field - delegateFieldCount); } }
@Override public void coerce(RecordCursor delegate, int field) { setLong(delegate.getLong(field)); } }
@Override public long getLong(int field) { if (coercers[field] == null) { return delegate.getLong(field); } return coercers[field].getLong(delegate, field); }
@Override protected void coerce(RecordCursor delegate, int field) { setDouble(intBitsToFloat((int) delegate.getLong(field))); } }
@Override public long getLong(int field) { return delegate.getLong(toDelegateField(field)); }
@Override public void coerce(RecordCursor delegate, int field) { setSlice(utf8Slice(String.valueOf(delegate.getLong(field)))); } }
@Override public long getLong(int field) { ColumnMapping columnMapping = columnMappings.get(field); if (columnMapping.getKind() == REGULAR) { return delegate.getLong(columnMapping.getIndex()); } return longs[field]; }
public static PrestoThriftBlock fromLongBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], long[], PrestoThriftBlock> result) { if (positions == 0) { return result.apply(null, null); } boolean[] nulls = null; long[] longs = null; RecordCursor cursor = recordSet.cursor(); for (int position = 0; position < positions; position++) { checkState(cursor.advanceNextPosition(), "cursor has less values than expected"); if (cursor.isNull(columnIndex)) { if (nulls == null) { nulls = new boolean[positions]; } nulls[position] = true; } else { if (longs == null) { longs = new long[positions]; } longs[position] = cursor.getLong(columnIndex); } } checkState(!cursor.advanceNextPosition(), "cursor has more values than expected"); return result.apply(nulls, longs); }
@Test public void testCursorMixedOrder() { RecordSet recordSet = new JdbcRecordSet(jdbcClient, session, split, ImmutableList.of( columnHandles.get("value"), columnHandles.get("value"), columnHandles.get("text"))); try (RecordCursor cursor = recordSet.cursor()) { assertEquals(cursor.getType(0), BIGINT); assertEquals(cursor.getType(1), BIGINT); assertEquals(cursor.getType(2), VARCHAR); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { assertEquals(cursor.getLong(0), cursor.getLong(1)); data.put(cursor.getSlice(2).toStringUtf8(), cursor.getLong(0)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("one", 1L) .put("two", 2L) .put("three", 3L) .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); } }
private static Object extractObject(RecordCursor cursor, int field, Type type) { if (cursor.isNull(field)) { return null; } Class<?> javaType = type.getJavaType(); if (javaType == boolean.class) { return cursor.getBoolean(field); } else if (javaType == long.class) { return cursor.getLong(field); } else if (javaType == double.class) { return cursor.getDouble(field); } else if (javaType == Slice.class) { return cursor.getSlice(field).toStringUtf8(); } throw new AssertionError("Unsupported type: " + type); }
private List<Long> readTimeStampsFrom(RecordSet recordSet) { ImmutableList.Builder<Long> result = ImmutableList.builder(); try (RecordCursor cursor = recordSet.cursor()) { while (cursor.advanceNextPosition()) { for (int i = 0; i < recordSet.getColumnTypes().size(); i++) { cursor.isNull(i); } if (cursor.isNull(0)) { return result.build(); } assertTrue(recordSet.getColumnTypes().get(0) instanceof TimestampType); result.add(cursor.getLong(0)); } } return result.build(); }
@Test public void testGetRecordSet() { ConnectorTransactionHandle transaction = new JdbcTransactionHandle(); JdbcRecordSetProvider recordSetProvider = new JdbcRecordSetProvider(jdbcClient); RecordSet recordSet = recordSetProvider.getRecordSet(transaction, SESSION, split, ImmutableList.of(textColumn, textShortColumn, valueColumn)); assertNotNull(recordSet, "recordSet is null"); RecordCursor cursor = recordSet.cursor(); assertNotNull(cursor, "cursor is null"); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(2)); assertEquals(cursor.getSlice(0), cursor.getSlice(1)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("one", 1L) .put("two", 2L) .put("three", 3L) .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
@Test public void testCursorMixedOrder() { RecordSet recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of( new ExampleColumnHandle("test", "value", BIGINT, 1), new ExampleColumnHandle("test", "value", BIGINT, 1), new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0))); RecordCursor cursor = recordSet.cursor(); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { assertEquals(cursor.getLong(0), cursor.getLong(1)); data.put(cursor.getSlice(2).toStringUtf8(), cursor.getLong(0)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
private Comparable<?> getPrestoValue(RecordCursor recordCursor, List<Column> columns, int columnId) { if (recordCursor.isNull(columnId)) { return null; } Column column = columns.get(columnId); ColumnType.Base baseType = column.getType().getBase(); switch (baseType) { case IDENTIFIER: case INTEGER: case DATE: case TIME: case DECIMAL: return recordCursor.getLong(columnId); case VARCHAR: case CHAR: return recordCursor.getSlice(columnId).toStringAscii(); } throw new UnsupportedOperationException(format("Unsupported TPCDS base type [%s]", baseType)); } }
@Test public void testGetRecordSet() { ExampleRecordSetProvider recordSetProvider = new ExampleRecordSetProvider(new ExampleConnectorId("test")); RecordSet recordSet = recordSetProvider.getRecordSet(ExampleTransactionHandle.INSTANCE, SESSION, new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of( new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0), new ExampleColumnHandle("test", "value", BIGINT, 1))); assertNotNull(recordSet, "recordSet is null"); RecordCursor cursor = recordSet.cursor(); assertNotNull(cursor, "cursor is null"); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(1)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
@Test public void testCursorSimple() { RecordSet recordSet = new ExampleRecordSet(new ExampleSplit("test", "schema", "table", dataUri), ImmutableList.of( new ExampleColumnHandle("test", "text", createUnboundedVarcharType(), 0), new ExampleColumnHandle("test", "value", BIGINT, 1))); RecordCursor cursor = recordSet.cursor(); assertEquals(cursor.getType(0), createUnboundedVarcharType()); assertEquals(cursor.getType(1), BIGINT); Map<String, Long> data = new LinkedHashMap<>(); while (cursor.advanceNextPosition()) { data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(1)); assertFalse(cursor.isNull(0)); assertFalse(cursor.isNull(1)); } assertEquals(data, ImmutableMap.<String, Long>builder() .put("ten", 10L) .put("eleven", 11L) .put("twelve", 12L) .build()); }
private static boolean fieldEquals(RecordCursor cursor, Field field1, Field field2) { checkArgument(cursor.getType(field1.getField()).equals(cursor.getType(field2.getField())), "Should only be comparing fields of the same type"); if (cursor.isNull(field1.getField()) || cursor.isNull(field2.getField())) { return false; } Class<?> javaType = cursor.getType(field1.getField()).getJavaType(); try { if (javaType == long.class) { return TRUE.equals((Boolean) field1.getEqualsMethodHandle().invokeExact(cursor.getLong(field1.getField()), cursor.getLong(field2.getField()))); } else if (javaType == double.class) { return TRUE.equals((Boolean) field1.getEqualsMethodHandle().invokeExact(cursor.getDouble(field1.getField()), cursor.getDouble(field2.getField()))); } else if (javaType == boolean.class) { return TRUE.equals((Boolean) field1.getEqualsMethodHandle().invokeExact(cursor.getBoolean(field1.getField()), cursor.getBoolean(field2.getField()))); } else if (javaType == Slice.class) { return TRUE.equals((Boolean) field1.getEqualsMethodHandle().invokeExact(cursor.getSlice(field1.getField()), cursor.getSlice(field2.getField()))); } else { return TRUE.equals((Boolean) field1.getEqualsMethodHandle().invoke(cursor.getObject(field1.getField()), cursor.getObject(field2.getField()))); } } catch (Throwable t) { throwIfUnchecked(t); throw new RuntimeException(t); } }