Search in sources :

Example 26 with StructType

use of org.apache.geode.cache.query.types.StructType in project geode by apache.

the class CompiledComparison method isConditioningNeededForIndex.

public boolean isConditioningNeededForIndex(RuntimeIterator independentIter, ExecutionContext context, boolean completeExpnsNeeded) throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
    IndexConditioningHelper ich = null;
    IndexInfo[] idxInfo = getIndexInfo(context);
    int indexFieldsSize = -1;
    boolean conditioningNeeded = true;
    if (idxInfo == null || idxInfo.length > 1) {
        return conditioningNeeded;
    }
    // assert idxInfo.length == 1;
    ObjectType indexRsltType = idxInfo[0]._index.getResultSetType();
    if (indexRsltType instanceof StructType) {
        indexFieldsSize = ((StructTypeImpl) indexRsltType).getFieldNames().length;
    } else {
        indexFieldsSize = 1;
    }
    if (independentIter != null && indexFieldsSize == 1) {
        ich = new IndexConditioningHelper(idxInfo[0], context, indexFieldsSize, completeExpnsNeeded, null, independentIter);
    }
    return ich == null || ich.shufflingNeeded;
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) StructType(org.apache.geode.cache.query.types.StructType) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl)

Example 27 with StructType

use of org.apache.geode.cache.query.types.StructType in project geode by apache.

the class CompiledGroupBySelect method createNewElementType.

private ObjectType createNewElementType(ObjectType elementType, boolean isStruct) {
    if (isStruct) {
        StructType oldType = (StructType) elementType;
        if (this.aggregateFunctions.length > 0) {
            ObjectType[] oldFieldTypes = oldType.getFieldTypes();
            ObjectType[] newFieldTypes = new ObjectType[oldFieldTypes.length];
            int i = 0;
            int aggFuncIndex = 0;
            for (ObjectType oldFieldType : oldFieldTypes) {
                if (this.aggregateColsPos.get(i)) {
                    newFieldTypes[i] = this.aggregateFunctions[aggFuncIndex++].getObjectType();
                } else {
                    newFieldTypes[i] = oldFieldType;
                }
                ++i;
            }
            return new StructTypeImpl(oldType.getFieldNames(), newFieldTypes);
        } else {
            return oldType;
        }
    } else {
        return this.aggregateFunctions.length > 0 ? this.aggregateFunctions[0].getObjectType() : elementType;
    }
}
Also used : ObjectType(org.apache.geode.cache.query.types.ObjectType) StructType(org.apache.geode.cache.query.types.StructType) StructTypeImpl(org.apache.geode.cache.query.internal.types.StructTypeImpl)

Example 28 with StructType

use of org.apache.geode.cache.query.types.StructType in project geode by apache.

the class PartitionedRegionQueryEvaluator method buildCumulativeResults.

private SelectResults buildCumulativeResults(boolean isDistinct, int limit) {
    // Indicates whether to check for PdxInstance and convert them to
    // domain object.
    // In case of local queries the domain objects are stored in the result set
    // for client/server queries PdxInstance are stored in result set.
    boolean getDomainObjectForPdx;
    // indicated results from remote nodes need to be deserialized
    // for local queries
    boolean getDeserializedObject = false;
    int numElementsInResult = 0;
    ObjectType elementType = this.cumulativeResults.getCollectionType().getElementType();
    boolean isStruct = elementType != null && elementType.isStructType();
    final DistributedMember me = this.pr.getMyId();
    if (DefaultQuery.testHook != null) {
        DefaultQuery.testHook.doTestHook(4);
    }
    boolean localResults = false;
    List<CumulativeNonDistinctResults.Metadata> collectionsMetadata = null;
    List<Collection> results = null;
    if (isDistinct) {
        if (isStruct) {
            StructType stype = (StructType) elementType;
            this.cumulativeResults = new StructSet(stype);
        } else {
            this.cumulativeResults = new ResultsSet(elementType);
        }
    } else {
        collectionsMetadata = new ArrayList<CumulativeNonDistinctResults.Metadata>();
        results = new ArrayList<Collection>();
    }
    for (Map.Entry<InternalDistributedMember, Collection<Collection>> e : this.resultsPerMember.entrySet()) {
        checkLowMemory();
        // retrieved on the client side.
        if (e.getKey().equals(me)) {
            // In case of local node query results, the objects are already in
            // domain object form
            getDomainObjectForPdx = false;
            localResults = true;
        // for select * queries on local node return deserialized objects
        } else {
            // In case of remote nodes, the result objects are in PdxInstance form
            // get domain objects for local queries.
            getDomainObjectForPdx = !(this.pr.getCache().getPdxReadSerializedByAnyGemFireServices());
            // deserialize the value
            if (!getDeserializedObject && !((DefaultQuery) this.query).isKeepSerialized()) {
                getDeserializedObject = true;
            }
        }
        final boolean isDebugEnabled = logger.isDebugEnabled();
        if (!isDistinct) {
            CumulativeNonDistinctResults.Metadata wrapper = CumulativeNonDistinctResults.getCollectionMetadata(getDomainObjectForPdx, getDeserializedObject, localResults);
            for (Collection res : e.getValue()) {
                results.add(res);
                collectionsMetadata.add(wrapper);
            }
        } else {
            for (Collection res : e.getValue()) {
                checkLowMemory();
                // final TaintableArrayList res = (TaintableArrayList) e.getValue();
                if (res != null) {
                    if (isDebugEnabled) {
                        logger.debug("Query Result from member :{}: {}", e.getKey(), res.size());
                    }
                    if (numElementsInResult == limit) {
                        break;
                    }
                    boolean[] objectChangedMarker = new boolean[1];
                    for (Object obj : res) {
                        checkLowMemory();
                        int occurence = 0;
                        obj = PDXUtils.convertPDX(obj, isStruct, getDomainObjectForPdx, getDeserializedObject, localResults, objectChangedMarker, true);
                        boolean elementGotAdded = isStruct ? ((StructSet) this.cumulativeResults).addFieldValues((Object[]) obj) : this.cumulativeResults.add(obj);
                        occurence = elementGotAdded ? 1 : 0;
                        // for non distinct query
                        if (occurence == 1) {
                            ++numElementsInResult;
                            // time and then exit. It will exit immediately on this return
                            if (numElementsInResult == limit) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    if (prQueryTraceInfoList != null && this.query.isTraced() && logger.isInfoEnabled()) {
        if (DefaultQuery.testHook != null) {
            DefaultQuery.testHook.doTestHook("Create PR Query Trace String");
        }
        StringBuilder sb = new StringBuilder();
        sb.append(LocalizedStrings.PartitionedRegion_QUERY_TRACE_LOG.toLocalizedString(this.query.getQueryString())).append("\n");
        for (PRQueryTraceInfo queryTraceInfo : prQueryTraceInfoList) {
            sb.append(queryTraceInfo.createLogLine(me)).append("\n");
        }
        logger.info(sb.toString());
        ;
    }
    if (!isDistinct) {
        this.cumulativeResults = new CumulativeNonDistinctResults(results, limit, this.cumulativeResults.getCollectionType().getElementType(), collectionsMetadata);
    }
    return this.cumulativeResults;
}
Also used : StructType(org.apache.geode.cache.query.types.StructType) ObjectType(org.apache.geode.cache.query.types.ObjectType) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)

Example 29 with StructType

use of org.apache.geode.cache.query.types.StructType in project geode by apache.

the class StructMemberAccessJUnitTest method testBugNumber_32355.

@Test
public void testBugNumber_32355() {
    String[] queries = { "select distinct positions.values.toArray[0], positions.values.toArray[0],status from /Portfolios" };
    int i = 0;
    try {
        for (i = 0; i < queries.length; i++) {
            Query q = CacheUtils.getQueryService().newQuery(queries[i]);
            Object r = q.execute();
            StructType type = ((StructType) ((SelectResults) r).getCollectionType().getElementType());
            String[] fieldNames = type.getFieldNames();
            for (i = 0; i < fieldNames.length; ++i) {
                String name = fieldNames[i];
                CacheUtils.log("Struct Field name = " + name);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(queries[i]);
    }
}
Also used : Query(org.apache.geode.cache.query.Query) StructType(org.apache.geode.cache.query.types.StructType) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with StructType

use of org.apache.geode.cache.query.types.StructType in project geode by apache.

the class StructMemberAccessJUnitTest method testBugNumber_32354.

@Test
public void testBugNumber_32354() {
    String[] queries = { "select distinct * from /root/portfolios.values, positions.values " };
    int i = 0;
    try {
        tearDown();
        CacheUtils.startCache();
        Region rootRegion = CacheUtils.createRegion("root", null);
        AttributesFactory attributesFactory = new AttributesFactory();
        attributesFactory.setValueConstraint(Portfolio.class);
        RegionAttributes regionAttributes = attributesFactory.create();
        Region region = rootRegion.createSubregion("portfolios", regionAttributes);
        for (i = 0; i < 4; i++) {
            region.put("" + i, new Portfolio(i));
        }
        for (i = 0; i < queries.length; i++) {
            Query q = CacheUtils.getQueryService().newQuery(queries[i]);
            Object r = q.execute();
            StructType type = ((StructType) ((SelectResults) r).getCollectionType().getElementType());
            String[] fieldNames = type.getFieldNames();
            for (i = 0; i < fieldNames.length; ++i) {
                String name = fieldNames[i];
                if (name.equals("/root/portfolios") || name.equals("positions.values")) {
                    fail("The field name in struct = " + name);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail(queries[i]);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) Query(org.apache.geode.cache.query.Query) StructType(org.apache.geode.cache.query.types.StructType) RegionAttributes(org.apache.geode.cache.RegionAttributes) Portfolio(org.apache.geode.cache.query.data.Portfolio) Region(org.apache.geode.cache.Region) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StructType (org.apache.geode.cache.query.types.StructType)47 ObjectType (org.apache.geode.cache.query.types.ObjectType)38 SelectResults (org.apache.geode.cache.query.SelectResults)36 Test (org.junit.Test)30 Iterator (java.util.Iterator)28 Query (org.apache.geode.cache.query.Query)28 Struct (org.apache.geode.cache.query.Struct)26 Region (org.apache.geode.cache.Region)25 QueryService (org.apache.geode.cache.query.QueryService)25 CompiledSelect (org.apache.geode.cache.query.internal.CompiledSelect)22 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)22 Portfolio (org.apache.geode.cache.query.data.Portfolio)15 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)14 HashSet (java.util.HashSet)13 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)11 List (java.util.List)8 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)7 ArrayList (java.util.ArrayList)6 ObjectTypeImpl (org.apache.geode.cache.query.internal.types.ObjectTypeImpl)4 ListIterator (java.util.ListIterator)3