|
47 | 47 | import org.apache.fluss.row.BinaryString; |
48 | 48 | import org.apache.fluss.row.GenericRow; |
49 | 49 | import org.apache.fluss.row.InternalRow; |
| 50 | +import org.apache.fluss.row.ProjectedRow; |
50 | 51 | import org.apache.fluss.row.indexed.IndexedRow; |
51 | 52 | import org.apache.fluss.types.BigIntType; |
52 | 53 | import org.apache.fluss.types.DataTypes; |
|
57 | 58 | import org.junit.jupiter.api.Disabled; |
58 | 59 | import org.junit.jupiter.api.Test; |
59 | 60 | import org.junit.jupiter.params.ParameterizedTest; |
| 61 | +import org.junit.jupiter.params.provider.Arguments; |
60 | 62 | import org.junit.jupiter.params.provider.CsvSource; |
| 63 | +import org.junit.jupiter.params.provider.MethodSource; |
61 | 64 | import org.junit.jupiter.params.provider.ValueSource; |
62 | 65 |
|
63 | 66 | import javax.annotation.Nullable; |
64 | 67 |
|
65 | 68 | import java.time.Duration; |
| 69 | +import java.time.LocalTime; |
66 | 70 | import java.util.ArrayList; |
67 | 71 | import java.util.Collections; |
68 | 72 | import java.util.Iterator; |
69 | 73 | import java.util.List; |
70 | 74 | import java.util.concurrent.CompletableFuture; |
| 75 | +import java.util.stream.Stream; |
71 | 76 |
|
72 | 77 | import static org.apache.fluss.client.table.scanner.batch.BatchScanUtils.collectRows; |
73 | 78 | import static org.apache.fluss.record.TestData.DATA1_ROW_TYPE; |
@@ -113,6 +118,58 @@ void testAppendOnly() throws Exception { |
113 | 118 | } |
114 | 119 | } |
115 | 120 |
|
| 121 | + private static Stream<Arguments> upsertTimeValueForAllPrecisionsArgs() { |
| 122 | + return Stream.of(Arguments.of(KvFormat.INDEXED), Arguments.of(KvFormat.COMPACTED)); |
| 123 | + } |
| 124 | + |
| 125 | + @ParameterizedTest |
| 126 | + @MethodSource("upsertTimeValueForAllPrecisionsArgs") |
| 127 | + void testUpsertTimeValueForAllPrecisions(KvFormat kvFormat) throws Exception { |
| 128 | + LocalTime time = LocalTime.of(10, 10, 10, 123000000); |
| 129 | + long mill = time.toNanoOfDay() / 1_000_000; |
| 130 | + |
| 131 | + // check for all precisions |
| 132 | + for (int i = 0; i <= 9; i++) { |
| 133 | + Schema schema = |
| 134 | + Schema.newBuilder() |
| 135 | + .column("a", DataTypes.TIME(i)) |
| 136 | + .column("b", DataTypes.INT()) |
| 137 | + .primaryKey("a", "b") |
| 138 | + .build(); |
| 139 | + TablePath tablePath = TablePath.of("test_db_" + i, "test_pk_table_" + i); |
| 140 | + TableDescriptor tableDescriptor = |
| 141 | + TableDescriptor.builder() |
| 142 | + .schema(schema) |
| 143 | + .property(ConfigOptions.TABLE_KV_FORMAT, kvFormat) |
| 144 | + .distributedBy(1) |
| 145 | + .build(); |
| 146 | + createTable(tablePath, tableDescriptor, false); |
| 147 | + try (Table table = conn.getTable(tablePath)) { |
| 148 | + UpsertWriter upsertWriter = table.newUpsert().createWriter(); |
| 149 | + upsertWriter.upsert(row((int) mill, 1)).get(); |
| 150 | + upsertWriter.flush(); |
| 151 | + |
| 152 | + LogScanner logScanner = createLogScanner(table); |
| 153 | + subscribeFromBeginning(logScanner, table); |
| 154 | + ScanRecords scanRecords = logScanner.poll(Duration.ofSeconds(1)); |
| 155 | + Integer scanResult = null; |
| 156 | + for (ScanRecord scanRecord : scanRecords) { |
| 157 | + InternalRow row = scanRecord.getRow(); |
| 158 | + scanResult = row.getInt(0); |
| 159 | + } |
| 160 | + |
| 161 | + Lookuper lookuper = table.newLookup().createLookuper(); |
| 162 | + ProjectedRow keyRow = ProjectedRow.from(schema.getPrimaryKeyIndexes()); |
| 163 | + keyRow.replaceRow(row((int) mill, 1)); |
| 164 | + InternalRow singletonRow = lookuper.lookup(keyRow).get().getSingletonRow(); |
| 165 | + assertThat(singletonRow).isNotNull(); |
| 166 | + Integer lookupResult = singletonRow.getInt(0); |
| 167 | + |
| 168 | + assertThat(scanResult).isEqualTo(lookupResult); |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + |
116 | 173 | @ParameterizedTest |
117 | 174 | @ValueSource(booleans = {true, false}) |
118 | 175 | @Disabled("TODO, fix me in #116") |
|
0 commit comments