Search in sources :

Example 16 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class TestJmxSplitManager method readTimeStampsFrom.

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();
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) ImmutableList(com.google.common.collect.ImmutableList) TimestampType(io.prestosql.spi.type.TimestampType)

Example 17 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class TestFieldSetFilteringRecordSet method test.

@Test
public void test() {
    ArrayType arrayOfBigintType = new ArrayType(BIGINT);
    FieldSetFilteringRecordSet fieldSetFilteringRecordSet = new FieldSetFilteringRecordSet(createTestMetadataManager().getFunctionAndTypeManager(), new InMemoryRecordSet(ImmutableList.of(BIGINT, BIGINT, TIMESTAMP_WITH_TIME_ZONE, TIMESTAMP_WITH_TIME_ZONE, arrayOfBigintType, arrayOfBigintType), ImmutableList.of(ImmutableList.of(100L, 100L, // test same time in different time zone to make sure equal check was done properly
    packDateTimeWithZone(100, getTimeZoneKeyForOffset(123)), packDateTimeWithZone(100, getTimeZoneKeyForOffset(234)), // test structural type
    arrayBlockOf(BIGINT, 12, 34, 56), arrayBlockOf(BIGINT, 12, 34, 56)))), ImmutableList.of(ImmutableSet.of(0, 1), ImmutableSet.of(2, 3), ImmutableSet.of(4, 5)));
    RecordCursor recordCursor = fieldSetFilteringRecordSet.cursor();
    assertTrue(recordCursor.advanceNextPosition());
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) RecordCursor(io.prestosql.spi.connector.RecordCursor) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) Test(org.testng.annotations.Test)

Example 18 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class TestFieldSetFilteringRecordSet method testMultipleFieldRecordSet.

@Test
public void testMultipleFieldRecordSet() {
    ArrayType arrayOfBigintType = new ArrayType(BIGINT);
    FieldSetFilteringRecordSet fieldSetFilteringRecordSet = new FieldSetFilteringRecordSet(createTestMetadataManager().getFunctionAndTypeManager(), new InMemoryRecordSet(ImmutableList.of(BIGINT, BIGINT, TIMESTAMP_WITH_TIME_ZONE, TIMESTAMP_WITH_TIME_ZONE, arrayOfBigintType, arrayOfBigintType), ImmutableList.of(ImmutableList.of(100L, 100L, // test same time in different time zone to make sure equal check was done properly
    packDateTimeWithZone(100, getTimeZoneKeyForOffset(123)), packDateTimeWithZone(100, getTimeZoneKeyForOffset(234)), // test structural type
    arrayBlockOf(BIGINT, 12, 34, 56), arrayBlockOf(BIGINT, 12, 34, 56)), ImmutableList.of(200L, 200L, // test same time in different time zone to make sure equal check was done properly
    packDateTimeWithZone(100, getTimeZoneKeyForOffset(123)), packDateTimeWithZone(100, getTimeZoneKeyForOffset(234)), // test structural type
    arrayBlockOf(BIGINT, 12, 34, 56), arrayBlockOf(BIGINT, 12, 34, 56)))), ImmutableList.of(ImmutableSet.of(0, 1), ImmutableSet.of(2, 3), ImmutableSet.of(4, 5)));
    RecordCursor recordCursor = fieldSetFilteringRecordSet.cursor();
    assertTrue(recordCursor.advanceNextPosition());
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) RecordCursor(io.prestosql.spi.connector.RecordCursor) InMemoryRecordSet(io.prestosql.spi.connector.InMemoryRecordSet) Test(org.testng.annotations.Test)

Example 19 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class TestLocalFileRecordSet method assertData.

private static void assertData(LocalFileTables localFileTables, LocalFileMetadata metadata) {
    LocalFileTableHandle tableHandle = new LocalFileTableHandle(LocalFileTables.HttpRequestLogTable.getSchemaTableName(), OptionalInt.of(0), OptionalInt.of(-1));
    List<LocalFileColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, tableHandle).values().stream().map(column -> (LocalFileColumnHandle) column).collect(Collectors.toList());
    LocalFileSplit split = new LocalFileSplit(address);
    RecordSet recordSet = new LocalFileRecordSet(localFileTables, split, tableHandle, columnHandles);
    RecordCursor cursor = recordSet.cursor();
    for (int i = 0; i < columnHandles.size(); i++) {
        assertEquals(cursor.getType(i), columnHandles.get(i).getColumnType());
    }
    // test one row
    assertTrue(cursor.advanceNextPosition());
    assertEquals(cursor.getSlice(0).toStringUtf8(), address.toString());
    assertEquals(cursor.getSlice(2).toStringUtf8(), "127.0.0.1");
    assertEquals(cursor.getSlice(3).toStringUtf8(), "POST");
    assertEquals(cursor.getSlice(4).toStringUtf8(), "/v1/memory");
    assertTrue(cursor.isNull(5));
    assertTrue(cursor.isNull(6));
    assertEquals(cursor.getLong(7), 200);
    assertEquals(cursor.getLong(8), 0);
    assertEquals(cursor.getLong(9), 1000);
    assertEquals(cursor.getLong(10), 10);
    assertTrue(cursor.isNull(11));
    assertTrue(cursor.advanceNextPosition());
    assertEquals(cursor.getSlice(0).toStringUtf8(), address.toString());
    assertEquals(cursor.getSlice(2).toStringUtf8(), "127.0.0.1");
    assertEquals(cursor.getSlice(3).toStringUtf8(), "GET");
    assertEquals(cursor.getSlice(4).toStringUtf8(), "/v1/service/presto/general");
    assertEquals(cursor.getSlice(5).toStringUtf8(), "foo");
    assertEquals(cursor.getSlice(6).toStringUtf8(), "ffffffff-ffff-ffff-ffff-ffffffffffff");
    assertEquals(cursor.getLong(7), 200);
    assertEquals(cursor.getLong(8), 0);
    assertEquals(cursor.getLong(9), 37);
    assertEquals(cursor.getLong(10), 1094);
    assertEquals(cursor.getSlice(11).toStringUtf8(), "a7229d56-5cbd-4e23-81ff-312ba6be0f12");
}
Also used : List(java.util.List) HostAddress(io.prestosql.spi.HostAddress) SESSION(io.prestosql.testing.TestingConnectorSession.SESSION) Assert.assertEquals(org.testng.Assert.assertEquals) Assert.assertTrue(org.testng.Assert.assertTrue) RecordCursor(io.prestosql.spi.connector.RecordCursor) Test(org.testng.annotations.Test) OptionalInt(java.util.OptionalInt) Collectors(java.util.stream.Collectors) RecordSet(io.prestosql.spi.connector.RecordSet) RecordCursor(io.prestosql.spi.connector.RecordCursor) RecordSet(io.prestosql.spi.connector.RecordSet)

Example 20 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class AbstractTestHive method assertPageSourceType.

protected static void assertPageSourceType(ConnectorPageSource connectorPageSource, HiveStorageFormat hiveStorageFormat) {
    ConnectorPageSource pageSource = connectorPageSource;
    if (pageSource instanceof OrcConcatPageSource) {
        pageSource = ((OrcConcatPageSource) pageSource).getConnectorPageSource();
    }
    if (pageSource instanceof RecordPageSource) {
        RecordCursor hiveRecordCursor = ((RecordPageSource) pageSource).getCursor();
        hiveRecordCursor = ((HiveRecordCursor) hiveRecordCursor).getRegularColumnRecordCursor();
        if (hiveRecordCursor instanceof HiveCoercionRecordCursor) {
            hiveRecordCursor = ((HiveCoercionRecordCursor) hiveRecordCursor).getRegularColumnRecordCursor();
        }
        assertInstanceOf(hiveRecordCursor, recordCursorType(hiveStorageFormat), hiveStorageFormat.name());
    } else {
        assertInstanceOf(((HivePageSource) pageSource).getPageSource(), pageSourceType(hiveStorageFormat), hiveStorageFormat.name());
    }
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) OrcConcatPageSource(io.prestosql.plugin.hive.orc.OrcConcatPageSource) ConnectorPageSource(io.prestosql.spi.connector.ConnectorPageSource) RecordPageSource(io.prestosql.spi.connector.RecordPageSource)

Aggregations

RecordCursor (io.prestosql.spi.connector.RecordCursor)27 Test (org.testng.annotations.Test)16 RecordSet (io.prestosql.spi.connector.RecordSet)10 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 Optional (java.util.Optional)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 Joiner (com.google.common.base.Joiner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)5 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)5 ArrayType (io.prestosql.spi.type.ArrayType)5 LinkedHashMap (java.util.LinkedHashMap)5 Slice (io.airlift.slice.Slice)4 RecordPageSource (io.prestosql.spi.connector.RecordPageSource)4 Assert.assertEquals (org.testng.Assert.assertEquals)4 Assert.assertTrue (org.testng.Assert.assertTrue)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Predicates.not (com.google.common.base.Predicates.not)3