Search in sources :

Example 1 with AbstractPojo

use of com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo in project hazelcast by hazelcast.

the class SqlOrderByTest method before.

@Before
public void before() {
    // Start members if needed
    if (members == null) {
        members = new ArrayList<>(membersCount);
        for (int i = 0; i < membersCount; ++i) {
            members.add(FACTORY.newHazelcastInstance(memberConfig()));
        }
    }
    if (isPortable()) {
        createMapping(members.get(0), mapName(), PORTABLE_FACTORY_ID, PORTABLE_VALUE_CLASS_ID, 0, PORTABLE_FACTORY_ID, PORTABLE_VALUE_CLASS_ID, 0);
    } else {
        createMapping(members.get(0), mapName(), keyClass(), valueClass());
    }
    // Get proper map
    IMap<Object, AbstractPojo> map = getTarget().getMap(mapName());
    // Populate map with values
    Map<Object, AbstractPojo> data = new HashMap<>();
    Random r = ThreadLocalRandom.current();
    int nextNullValue = Math.max(1, r.nextInt(5));
    int nextSameValues = Math.max(1, r.nextInt(5));
    long idx = Math.negateExact(DATA_SET_MAX_POSITIVE);
    int skipFirstPositiveEntries = 20;
    while (idx < DATA_SET_MAX_POSITIVE) {
        if (idx % nextNullValue == 0 && idx >= skipFirstPositiveEntries) {
            data.put(key(idx++), value());
            nextNullValue = Math.max(1, r.nextInt(5));
        } else if (idx % nextSameValues == 0 && idx >= skipFirstPositiveEntries) {
            int sameValuesCount = r.nextInt(5);
            long value = idx;
            while (sameValuesCount > 0 && idx < DATA_SET_MAX_POSITIVE) {
                data.put(key(idx++), value(value));
                sameValuesCount--;
            }
            nextSameValues = Math.max(1, r.nextInt(5));
        } else {
            data.put(key(idx), value(idx));
            idx++;
        }
    }
    map.putAll(data);
    // Populate stable map data
    Map<Object, AbstractPojo> stableData = new HashMap<>();
    idx = 0;
    while (idx < DATA_SET_SIZE) {
        stableData.put(key(idx), value(idx));
        idx++;
    }
    if (isPortable()) {
        createMapping(members.get(0), stableMapName(), PORTABLE_FACTORY_ID, PORTABLE_VALUE_CLASS_ID, 0, PORTABLE_FACTORY_ID, PORTABLE_VALUE_CLASS_ID, 0);
    } else {
        createMapping(members.get(0), stableMapName(), keyClass(), valueClass());
    }
    IMap<Object, AbstractPojo> stableMap = getTarget().getMap(stableMapName());
    stableMap.putAll(stableData);
}
Also used : AbstractPojo(com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) HashMap(java.util.HashMap) Before(org.junit.Before)

Example 2 with AbstractPojo

use of com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo in project hazelcast by hazelcast.

the class SqlOrderByTest method addIndex.

private void addIndex(List<String> fieldNames, IndexType type, String mapName) {
    IMap<Object, AbstractPojo> map = getTarget().getMap(mapName);
    IndexConfig indexConfig = new IndexConfig().setName("Index_" + randomName()).setType(type);
    for (String fieldName : fieldNames) {
        indexConfig.addAttribute(fieldName);
    }
    map.addIndex(indexConfig);
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) AbstractPojo(com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo)

Example 3 with AbstractPojo

use of com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo in project hazelcast by hazelcast.

the class SqlOrderByTest method checkSelectWithOrderBy.

private void checkSelectWithOrderBy(List<String> indexAttrs, String sql, List<String> checkOrderFields, List<Boolean> orderDirections) {
    IMap<Object, AbstractPojo> map = getTarget().getMap(mapName());
    IndexConfig indexConfig = new IndexConfig().setName("Index_" + randomName()).setType(SORTED);
    for (String indexAttr : indexAttrs) {
        indexConfig.addAttribute(indexAttr);
    }
    map.addIndex(indexConfig);
    assertEquals(DATA_SET_SIZE, map.size());
    assertSqlResultOrdered(sql, checkOrderFields, orderDirections, map.size());
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) AbstractPojo(com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo)

Example 4 with AbstractPojo

use of com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo in project hazelcast by hazelcast.

the class SqlOrderByTest method checkSelectWithOrderBy.

protected void checkSelectWithOrderBy(List<String> indexAttrs, List<String> orderFields, List<Boolean> orderDirections) {
    IMap<Object, AbstractPojo> map = getTarget().getMap(mapName());
    IndexConfig indexConfig = new IndexConfig().setName("Index_" + randomName()).setType(SORTED);
    for (String indexAttr : indexAttrs) {
        indexConfig.addAttribute(indexAttr);
    }
    if (indexAttrs.size() > 0) {
        map.addIndex(indexConfig);
    }
    assertEquals(DATA_SET_SIZE, map.size());
    StringBuilder orders = new StringBuilder();
    for (int i = 0; i < orderFields.size(); ++i) {
        String orderField = orderFields.get(i);
        Boolean descending = orderDirections.get(i);
        orders.append(orderField);
        if (descending != null) {
            orders.append(descending ? " DESC " : " ASC ");
        }
        if (i < orderFields.size() - 1) {
            orders.append(", ");
        }
    }
    String sql = sqlWithOrderBy(orders.toString());
    assertSqlResultOrdered(sql, orderFields, orderDirections, map.size());
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) AbstractPojo(com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo)

Aggregations

AbstractPojo (com.hazelcast.jet.sql.SqlBasicTest.AbstractPojo)4 IndexConfig (com.hazelcast.config.IndexConfig)3 HashMap (java.util.HashMap)1 Random (java.util.Random)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Before (org.junit.Before)1