Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-20478 Sql. Get rid of UNSPECIFIED_VALUE_PLACEHOLDER #2671

Merged
merged 13 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ItSecondaryIndexTest extends ClusterPerClassIntegrationTest {
* Before all.
*/
@BeforeAll
static void initTestData() throws InterruptedException {
static void initTestData() {
sql("CREATE TABLE developer (id INT PRIMARY KEY, name VARCHAR, depid INT, city VARCHAR, age INT)");
sql("CREATE INDEX " + DEPID_IDX + " ON developer (depid)");
sql("CREATE INDEX " + NAME_CITY_IDX + " ON developer (name DESC, city DESC)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.apache.ignite.internal.sql.engine.exec;

import static org.apache.ignite.internal.sql.engine.exec.exp.ExpressionFactoryImpl.UNSPECIFIED_VALUE_PLACEHOLDER;

import java.nio.ByteBuffer;
import java.util.List;
import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
Expand All @@ -31,7 +29,6 @@
import org.apache.ignite.internal.sql.engine.schema.TableDescriptor;
import org.apache.ignite.internal.sql.engine.util.TypeUtils;
import org.apache.ignite.internal.type.NativeTypeSpec;
import org.apache.ignite.internal.util.IgniteUtils;

/**
* Helper class provides method to convert binary tuple to rows and vice-versa.
Expand Down Expand Up @@ -59,7 +56,7 @@ public static BinaryTupleSchema createIndexRowSchema(List<String> indexedColumns
* @param <RowT> Row type.
* @return Binary tuple.
*/
public static <RowT> BinaryTuplePrefix toBinaryTuplePrefix(
static <RowT> BinaryTuplePrefix toBinaryTuplePrefix(
ExecutionContext<RowT> ectx,
BinaryTupleSchema binarySchema,
RowHandler.RowFactory<RowT> factory,
Expand All @@ -70,20 +67,11 @@ public static <RowT> BinaryTuplePrefix toBinaryTuplePrefix(
int indexedColumnsCount = binarySchema.elementCount();
int prefixColumnsCount = handler.columnCount(searchRow);

assert prefixColumnsCount == indexedColumnsCount : "Invalid range condition";

int specifiedCols = 0;
for (int i = 0; i < prefixColumnsCount; i++) {
if (handler.get(i, searchRow) == UNSPECIFIED_VALUE_PLACEHOLDER) {
break;
}

specifiedCols++;
}
assert binarySchema.elementCount() >= prefixColumnsCount : "Invalid range condition";

BinaryTuplePrefixBuilder tupleBuilder = new BinaryTuplePrefixBuilder(specifiedCols, indexedColumnsCount);
BinaryTuplePrefixBuilder tupleBuilder = new BinaryTuplePrefixBuilder(prefixColumnsCount, indexedColumnsCount);

return new BinaryTuplePrefix(indexedColumnsCount, toByteBuffer(ectx, binarySchema, handler, tupleBuilder, searchRow));
return new BinaryTuplePrefix(indexedColumnsCount, toByteBuffer(binarySchema, handler, tupleBuilder, searchRow));
}

/**
Expand All @@ -108,21 +96,12 @@ public static <RowT> BinaryTuple toBinaryTuple(

assert rowColumnsCount == binarySchema.elementCount() : "Invalid lookup key.";

if (IgniteUtils.assertionsEnabled()) {
for (int i = 0; i < rowColumnsCount; i++) {
if (handler.get(i, searchRow) == UNSPECIFIED_VALUE_PLACEHOLDER) {
throw new AssertionError("Invalid lookup key.");
}
}
}

BinaryTupleBuilder tupleBuilder = new BinaryTupleBuilder(rowColumnsCount);

return new BinaryTuple(rowColumnsCount, toByteBuffer(ectx, binarySchema, handler, tupleBuilder, searchRow));
return new BinaryTuple(rowColumnsCount, toByteBuffer(binarySchema, handler, tupleBuilder, searchRow));
}

private static <RowT> ByteBuffer toByteBuffer(
ExecutionContext<RowT> ectx,
BinaryTupleSchema binarySchema,
RowHandler<RowT> handler,
BinaryTupleBuilder tupleBuilder,
Expand All @@ -133,10 +112,6 @@ private static <RowT> ByteBuffer toByteBuffer(
for (int i = 0; i < columnsCount; i++) {
Object val = handler.get(i, searchRow);

if (val == UNSPECIFIED_VALUE_PLACEHOLDER) {
break; // No more columns in prefix.
}

Element element = binarySchema.element(i);

val = TypeUtils.fromInternal(val, NativeTypeSpec.toClass(element.typeSpec(), element.nullable()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,20 @@ public <RowT> Publisher<RowT> indexLookup(
return new TransformingPublisher<>(pub, item -> rowConverter.toRow(ctx, item, rowFactory));
}

private <RowT> @Nullable BinaryTuplePrefix toBinaryTuplePrefix(ExecutionContext<RowT> ctx,
private static <RowT> @Nullable BinaryTuplePrefix toBinaryTuplePrefix(
ExecutionContext<RowT> ctx,
BinaryTupleSchema indexRowSchema,
@Nullable RowT condition, RowFactory<RowT> factory) {

@Nullable RowT condition,
RowFactory<RowT> factory
) {
if (condition == null) {
return null;
}

return RowConverter.toBinaryTuplePrefix(ctx, indexRowSchema, factory, condition);
}

private <RowT> @Nullable BinaryTuple toBinaryTuple(ExecutionContext<RowT> ctx, BinaryTupleSchema indexRowSchema,
private static <RowT> @Nullable BinaryTuple toBinaryTuple(ExecutionContext<RowT> ctx, BinaryTupleSchema indexRowSchema,
@Nullable RowT condition, RowFactory<RowT> factory) {
if (condition == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.ignite.internal.sql.engine.exec;

import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
import static org.apache.ignite.internal.sql.engine.exec.exp.ExpressionFactoryImpl.UNSPECIFIED_VALUE_PLACEHOLDER;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand Down Expand Up @@ -233,8 +232,6 @@ ByteBuffer toByteBuffer() {
for (int i = 0; i < row.length; i++) {
Object value = row[i];

assert value != UNSPECIFIED_VALUE_PLACEHOLDER : "Invalid row value.";

appendValue(tupleBuilder, rowSchema.fields().get(i), value);
}

Expand Down
Loading