Skip to content

Commit

Permalink
add size base range v2
Browse files Browse the repository at this point in the history
1. merge size and quantity logic
2. add calcutor size basing datetype logic to improve performance
  • Loading branch information
wg1026688210 committed Jan 24, 2024
1 parent 8c6fc2c commit 2644b4a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,4 @@ public BiFunction<DataGetters, Integer, Integer> visit(RowType rowType) {
}
};
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.paimon.types;

import org.apache.paimon.data.BinaryString;
Expand All @@ -18,9 +36,7 @@
import java.util.function.BiFunction;
import java.util.stream.Collectors;

/**
* Test for subclasses of InternalRowToSizeVisitor.
*/
/** Test for subclasses of InternalRowToSizeVisitor. */
public class InternalRowToSizeVisitorTest {

private List<BiFunction<DataGetters, Integer, Integer>> feildSizeCalculator;
Expand Down Expand Up @@ -77,9 +93,10 @@ void setUp() {
.build();

InternalRowToSizeVisitor internalRowToSizeVisitor = new InternalRowToSizeVisitor();
feildSizeCalculator = rowType.getFieldTypes().stream().map(
dataType -> dataType.accept(internalRowToSizeVisitor)
).collect(Collectors.toList());
feildSizeCalculator =
rowType.getFieldTypes().stream()
.map(dataType -> dataType.accept(internalRowToSizeVisitor))
.collect(Collectors.toList());
}

@Test
Expand All @@ -104,7 +121,7 @@ void testCalculatorSize() {
row.setField(5, 0.5D);
Assertions.assertThat(feildSizeCalculator.get(5).apply(row, 5)).isEqualTo(8);

row.setField(6, new GenericArray(new Object[]{BinaryString.fromString("1")}));
row.setField(6, new GenericArray(new Object[] {BinaryString.fromString("1")}));
Assertions.assertThat(feildSizeCalculator.get(6).apply(row, 6)).isEqualTo(1);

row.setField(7, BinaryString.fromString("3"));
Expand All @@ -131,7 +148,7 @@ void testCalculatorSize() {
row.setField(14, Decimal.fromBigDecimal(new BigDecimal("0.22"), 3, 3));
Assertions.assertThat(feildSizeCalculator.get(14).apply(row, 14)).isEqualTo(2);

row.setField(15, new byte[]{1, 5, 2});
row.setField(15, new byte[] {1, 5, 2});
Assertions.assertThat(feildSizeCalculator.get(15).apply(row, 15)).isEqualTo(3);

row.setField(16, 0.26F);
Expand All @@ -154,12 +171,10 @@ void testCalculatorSize() {
Assertions.assertThat(feildSizeCalculator.get(20).apply(row, 20)).isEqualTo(2);

row.setField(
21,
new GenericMap(Collections.singletonMap(BinaryString.fromString("set"), 1)));
21, new GenericMap(Collections.singletonMap(BinaryString.fromString("set"), 1)));

Assertions.assertThat(feildSizeCalculator.get(21).apply(row, 21)).isEqualTo(3);


row.setField(
22,
GenericRow.of(
Expand All @@ -168,11 +183,10 @@ void testCalculatorSize() {
Collections.singletonMap(
BinaryString.fromString("k"),
BinaryString.fromString("v"))),
new GenericArray(new Object[]{BinaryString.fromString("1")}),
new GenericArray(new Object[] {BinaryString.fromString("1")}),
new GenericMap(
Collections.singletonMap(
BinaryString.fromString("set"), 1)))));
Assertions.assertThat(feildSizeCalculator.get(22).apply(row, 22)).isEqualTo(6);
}

}
}

0 comments on commit 2644b4a

Please sign in to comment.