Search in sources :

Example 6 with ExpressionBiValue

use of com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue in project hazelcast by hazelcast.

the class SqlIndexAbstractTest method fill.

private void fill() {
    // Create an object with non-null fields to initialize converters
    for (int i = 0; i < instances().length; ++i) {
        int key = getLocalKeys(instances()[i], 1, value -> value).get(0);
        ExpressionBiValue value = ExpressionBiValue.createBiValue(valueClass, key, f1.valueFrom(), f2.valueFrom());
        map.put(key, value);
        map.remove(key);
    }
    // Fill with values
    int keyCounter = 0;
    localMap = new HashMap();
    for (Object firstField : f1.values()) {
        for (Object secondField : f2.values()) {
            // Put the same value twice intentionally to test index key with multiple values
            for (int i = 0; i < 2 * DEFAULT_MEMBERS_COUNT; i++) {
                int key = keyCounter++;
                ExpressionBiValue value = ExpressionBiValue.createBiValue(valueClass, key, firstField, secondField);
                localMap.put(key, value);
            }
        }
    }
    map.putAll(localMap);
}
Also used : Arrays(java.util.Arrays) MapConfig(com.hazelcast.config.MapConfig) HazelcastTable(com.hazelcast.jet.sql.impl.schema.HazelcastTable) ExpressionPredicates.gte_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.gte_2) ExpressionPredicates.isNull_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.isNull_2) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OptimizerTestSupport(com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ExpressionPredicates.eq(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.eq) Assert.fail(org.junit.Assert.fail) SqlRow(com.hazelcast.sql.SqlRow) Parameterized(org.junit.runners.Parameterized) ExpressionPredicates.eq_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.eq_2) ExpressionPredicates.gt_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.gt_2) ExpressionPredicates.and(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.and) Predicate(java.util.function.Predicate) Collection(java.util.Collection) MapTableUtils.getPartitionedMapIndexes(com.hazelcast.sql.impl.schema.map.MapTableUtils.getPartitionedMapIndexes) Set(java.util.Set) ExpressionPredicates.lte(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.lte) ExpressionValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionValue) ExpressionPredicates.isNotNull_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.isNotNull_2) IndexConfig(com.hazelcast.config.IndexConfig) List(java.util.List) FullScanLogicalRel(com.hazelcast.jet.sql.impl.opt.logical.FullScanLogicalRel) MapTableField(com.hazelcast.sql.impl.schema.map.MapTableField) SqlResult(com.hazelcast.sql.SqlResult) ExpressionType(com.hazelcast.jet.sql.impl.support.expressions.ExpressionType) BeforeClass(org.junit.BeforeClass) SqlStatement(com.hazelcast.sql.SqlStatement) QueryDataType(com.hazelcast.sql.impl.type.QueryDataType) ExpressionPredicates.gt(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.gt) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) HashMap(java.util.HashMap) ExpressionPredicates.isNotNull(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.isNotNull) ExpressionPredicates.isNull(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.isNull) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IndexType(com.hazelcast.config.IndexType) QueryPath(com.hazelcast.sql.impl.extract.QueryPath) ExpressionPredicates.or(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.or) Before(org.junit.Before) ExpressionPredicates.gte(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.gte) ExpressionPredicates.neq(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.neq) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IndexScanMapPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.IndexScanMapPhysicalRel) FullScanPhysicalRel(com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel) ExpressionPredicates.lte_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.lte_2) TableField(com.hazelcast.sql.impl.schema.TableField) ExpressionPredicates.lt(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.lt) ExpressionPredicates.lt_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.lt_2) ExpressionPredicates.neq_2(com.hazelcast.jet.sql.impl.support.expressions.ExpressionPredicates.neq_2) IMap(com.hazelcast.map.IMap) HashMap(java.util.HashMap) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)

Example 7 with ExpressionBiValue

use of com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue in project hazelcast by hazelcast.

the class SqlIndexConverterMismatchTest method testMismatch.

/**
 * @see MapIndexScanExecIterator#getIndexEntries
 */
@SuppressWarnings({ "StatementWithEmptyBody", "JavadocReference" })
@Ignore("https://github.com/hazelcast/hazelcast/issues/19287")
@Test
public void testMismatch() {
    ExpressionBiValue value1 = new ExpressionBiValue.IntegerIntegerVal();
    value1.field1(10);
    value1.field2(10);
    ExpressionBiValue value2 = new ExpressionBiValue.StringIntegerVal();
    value2.field1("10");
    value2.field2(10);
    map.put(getLocalKey(member1, key -> key), value1);
    map.put(getLocalKey(member2, key -> key), value2);
    try {
        try (SqlResult result = member1.getSql().execute("SELECT key FROM " + MAP_NAME + " WHERE field1=1")) {
            for (SqlRow ignore : result) {
            // No-op.
            }
        }
        fail("Must fail!");
    } catch (HazelcastSqlException e) {
        assertEquals(SqlErrorCode.INDEX_INVALID, e.getCode());
        Throwable ex = findRootQueryException(e);
        assertEquals("Cannot use the index \"index\" of the IMap \"map\" because it has component \"field1\" of type VARCHAR, but INTEGER was expected", ex.getMessage());
    }
}
Also used : ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) ArrayList(java.util.ArrayList) MapConfig(com.hazelcast.config.MapConfig) IndexType(com.hazelcast.config.IndexType) MapIndexScanExecIterator(com.hazelcast.sql.impl.exec.scan.index.MapIndexScanExecIterator) After(org.junit.After) Assert.fail(org.junit.Assert.fail) SqlRow(com.hazelcast.sql.SqlRow) Parameterized(org.junit.runners.Parameterized) QueryException(com.hazelcast.sql.impl.QueryException) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) Collection(java.util.Collection) HazelcastParallelParametersRunnerFactory(com.hazelcast.test.HazelcastParallelParametersRunnerFactory) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) IndexConfig(com.hazelcast.config.IndexConfig) List(java.util.List) Ignore(org.junit.Ignore) SqlResult(com.hazelcast.sql.SqlResult) SqlErrorCode(com.hazelcast.sql.impl.SqlErrorCode) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) SqlRow(com.hazelcast.sql.SqlRow) SqlResult(com.hazelcast.sql.SqlResult) ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue) HazelcastSqlException(com.hazelcast.sql.HazelcastSqlException) Ignore(org.junit.Ignore) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with ExpressionBiValue

use of com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue in project hazelcast by hazelcast.

the class CaseOperatorIntegrationTest method putBiValue.

private void putBiValue(Object field1, Object field2, ExpressionType<?> type1, ExpressionType<?> type2) {
    ExpressionBiValue value = ExpressionBiValue.createBiValue(ExpressionBiValue.createBiClass(type1, type2), field1, field2);
    put(value);
}
Also used : ExpressionBiValue(com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)

Aggregations

ExpressionBiValue (com.hazelcast.jet.sql.impl.support.expressions.ExpressionBiValue)8 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Test (org.junit.Test)4 IMap (com.hazelcast.map.IMap)3 HazelcastSqlException (com.hazelcast.sql.HazelcastSqlException)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 IndexConfig (com.hazelcast.config.IndexConfig)2 IndexType (com.hazelcast.config.IndexType)2 MapConfig (com.hazelcast.config.MapConfig)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Config (com.hazelcast.config.Config)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 OptimizerTestSupport (com.hazelcast.jet.sql.impl.opt.OptimizerTestSupport)1 FullScanLogicalRel (com.hazelcast.jet.sql.impl.opt.logical.FullScanLogicalRel)1 FullScanPhysicalRel (com.hazelcast.jet.sql.impl.opt.physical.FullScanPhysicalRel)1