Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -204,7 +204,7 @@ protected TreeIndex<IndexRow> treeIndex() {
}

/** From Row to IndexRow convertor. */
protected IndexRow row2indexRow(Row bound) {
protected @Nullable IndexRow row2indexRow(Row bound) {
if (bound == null)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.util.Map;
import org.apache.calcite.util.ImmutableBitSet;
import org.apache.calcite.util.ImmutableIntList;
import org.apache.ignite.IgniteException;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.binary.BinaryObjectException;
import org.apache.ignite.internal.binary.BinaryContext;
import org.apache.ignite.internal.binary.BinaryUtils;
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition;
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType;
import org.apache.ignite.internal.cache.query.index.sorted.IndexPlainRowImpl;
Expand Down Expand Up @@ -54,7 +56,7 @@ public IndexWrappedKeyScan(
}

/** */
@Override protected IndexRow row2indexRow(Row bound) {
@Override @Nullable protected IndexRow row2indexRow(Row bound) {
if (bound == null)
return null;

Expand All @@ -63,22 +65,34 @@ public IndexWrappedKeyScan(
Object key = rowHnd.get(QueryUtils.KEY_COL, bound);
assert key != null : String.format("idxName=%s, bound=%s", idx.name(), Commons.toString(rowHnd, bound));

if (!idx.indexDefinition().typeDescriptor().keyTypeName().equals(key.getClass().getName()))
return null;

if (key instanceof BinaryObject)
return binaryObject2indexRow((BinaryObject)key);
else {
if (!idx.indexDefinition().typeDescriptor().keyTypeName().equals(key.getClass().getName()))
return null;

BinaryContext bCtx = cctx.kernalContext().marshaller().binaryMarshaller().context();
byte[] keyObj;

try {
keyObj = cctx.kernalContext().marshaller().binaryMarshaller().marshal(key, true);
}
catch (BinaryObjectException ex) {
// unregistered class ?
return null;
}

throw new IgniteException(String.format(
"Unsupported type for index boundary: [expected=%s, current=%s]",
BinaryObject.class.getName(), key.getClass().getName()
));
BinaryObject keyBinary = BinaryUtils.binariesFactory.binaryObject(bCtx, keyObj);

return binaryObject2indexRow(keyBinary);
}
}

/** */
private IndexRow binaryObject2indexRow(BinaryObject o) {
assert o.type().typeName().equals(idx.indexDefinition().typeDescriptor().keyTypeName()) : String.format(
"idx=%s, o=%s, oType=%s, idxKeyType=%s",
idx.name(), o, o.type().typeName(), idx.indexDefinition().typeDescriptor().keyTypeName()
);

InlineIndexRowHandler idxRowHnd = idx.segment(0).rowHandler();
IndexKey[] keys = new IndexKey[idx.indexDefinition().indexKeyDefinitions().size()];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.function.BiPredicate;
import org.apache.calcite.DataContext;
import org.apache.calcite.avatica.util.ByteString;
import org.apache.calcite.config.CalciteConnectionConfig;
Expand All @@ -34,6 +35,8 @@
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.ignite.binary.BinaryObject;
import org.apache.ignite.internal.binary.BinaryObjectImpl;
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeSystem;
import org.apache.ignite.internal.processors.query.calcite.util.Commons;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -119,15 +122,15 @@ public static BigDecimal toBigDecimal(boolean val, int precision, int scale) {
}

/** CAST(VARCHAR AS DECIMAL). */
public static BigDecimal toBigDecimal(String s, int precision, int scale) {
public static @Nullable BigDecimal toBigDecimal(String s, int precision, int scale) {
if (s == null)
return null;

return toBigDecimal(new BigDecimal(s.trim()), precision, scale);
}

/** Converts {@code val} to a {@link BigDecimal} with the given {@code precision} and {@code scale}. */
public static BigDecimal toBigDecimal(Number val, int precision, int scale) {
public static @Nullable BigDecimal toBigDecimal(Number val, int precision, int scale) {
assert precision > 0 : "Invalid precision: " + precision;
assert scale >= 0 : "Invalid scale: " + scale;

Expand All @@ -146,7 +149,7 @@ public static BigDecimal toBigDecimal(Number val, int precision, int scale) {
}

/** Cast object depending on type to DECIMAL. */
public static BigDecimal toBigDecimal(Object o, int precision, int scale) {
public static @Nullable BigDecimal toBigDecimal(Object o, int precision, int scale) {
if (o == null)
return null;

Expand Down Expand Up @@ -297,49 +300,59 @@ private long convertToLongArg(Object val, String name) {

/** SQL >=. */
public static boolean geAny(Object a, Object b) {
if (Commons.isBinaryComparable(a, b))
return Commons.compareBinary(a, b) >= 0;

return SqlFunctions.geAny(a, b);
return binaryAwareCompare(a, b, (f, s) -> Commons.compareBinary(f, s) >= 0, SqlFunctions::geAny);
}

/** SQL >. */
public static boolean gtAny(Object a, Object b) {
if (Commons.isBinaryComparable(a, b))
return Commons.compareBinary(a, b) > 0;

return SqlFunctions.gtAny(a, b);
return binaryAwareCompare(a, b, (f, s) -> Commons.compareBinary(f, s) > 0, SqlFunctions::gtAny);
}

/** SQL <=. */
public static boolean leAny(Object a, Object b) {
if (Commons.isBinaryComparable(a, b))
return Commons.compareBinary(a, b) <= 0;

return SqlFunctions.leAny(a, b);
return binaryAwareCompare(a, b, (f, s) -> Commons.compareBinary(f, s) <= 0, SqlFunctions::leAny);
}

/** SQL <. */
public static boolean ltAny(Object a, Object b) {
if (Commons.isBinaryComparable(a, b))
return Commons.compareBinary(a, b) < 0;

return SqlFunctions.ltAny(a, b);
return binaryAwareCompare(a, b, (f, s) -> Commons.compareBinary(f, s) < 0, SqlFunctions::ltAny);
}

/** SQL =. */
public static boolean eqAny(Object a, Object b) {
if (Commons.isBinaryComparable(a, b))
return Commons.compareBinary(a, b) == 0;

return SqlFunctions.eqAny(a, b);
return binaryAwareCompare(a, b, (f, s) -> Commons.compareBinary(f, s) == 0, SqlFunctions::eqAny);
}

/** SQL <>. */
public static boolean neAny(Object a, Object b) {
if (Commons.isBinaryComparable(a, b))
return Commons.compareBinary(a, b) != 0;
return binaryAwareCompare(a, b, (f, s) -> Commons.compareBinary(f, s) != 0, SqlFunctions::neAny);
}

/** */
private static boolean binaryAwareCompare(
Object first,
Object second,
BiPredicate<BinaryObject, BinaryObject> binComp,
BiPredicate<Object, Object> anyComp
) {
boolean firstBinary = first instanceof BinaryObjectImpl;
boolean secondBinary = second instanceof BinaryObjectImpl;

if (firstBinary) {
if (secondBinary)
return binComp.test((BinaryObject)first, (BinaryObject)second);
else {
Object firstObj = ((BinaryObject)first).deserialize();
return anyComp.test(firstObj, second);
}
}
else {
if (secondBinary) {
Object secondObj = ((BinaryObject)second).deserialize();
return anyComp.test(first, secondObj);
}
}

return SqlFunctions.neAny(a, b);
return anyComp.test(first, second);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private <Row> Object insertVal(Row row, ExecutionContext<Row> ectx) throws Ignit
}

/** */
private Object newVal(String typeName) throws IgniteCheckedException {
private Object newVal(String typeName) {
GridCacheContext<?, ?> cctx = cacheContext();

BinaryObjectBuilder builder = cctx.grid().binary().builder(typeName);
Expand Down
Loading
Loading