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;
}
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;
}
}
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;
}
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]);
}
}
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]);
}
}
Aggregations