Skip to content
Closed
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
45 changes: 17 additions & 28 deletions modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.LinkedHashMap;
import java.util.Objects;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.cache.query.QueryIndexMessage;
import org.apache.ignite.internal.util.typedef.internal.S;

/**
Expand All @@ -31,7 +31,7 @@
* the list can be provided as following {@code (id, name asc, age desc)}.
*/
@SuppressWarnings("TypeMayBeWeakened")
public class QueryIndex implements Serializable {
public class QueryIndex extends QueryIndexMessage implements Serializable {
/** */
private static final long serialVersionUID = 0L;

Expand All @@ -41,24 +41,12 @@ public class QueryIndex implements Serializable {
/** Default index inline size. */
public static final int DFLT_INLINE_SIZE = -1;

/** Index name. */
private String name;

/** */
@GridToStringInclude
private LinkedHashMap<String, Boolean> fields;

/** */
private QueryIndexType type = DFLT_IDX_TYP;

/** */
private int inlineSize = DFLT_INLINE_SIZE;

/**
* Creates an empty index. Should be populated via setters.
*/
public QueryIndex() {
// Empty constructor.
type = DFLT_IDX_TYP;
inlineSize = DFLT_INLINE_SIZE;
}

/**
Expand Down Expand Up @@ -114,10 +102,10 @@ public QueryIndex(String field, QueryIndexType type) {
* @param asc Ascending flag.
*/
public QueryIndex(String field, QueryIndexType type, boolean asc) {
fields = new LinkedHashMap<>();
fields.put(field, asc);

inlineSize = DFLT_INLINE_SIZE;
this.type = type;

addField(field, asc);
}

/**
Expand All @@ -129,11 +117,11 @@ public QueryIndex(String field, QueryIndexType type, boolean asc) {
* @param name Index name.
*/
public QueryIndex(String field, QueryIndexType type, boolean asc, String name) {
fields = new LinkedHashMap<>();
fields.put(field, asc);

inlineSize = DFLT_INLINE_SIZE;
this.type = type;
this.name = name;

addField(field, asc);
}

/**
Expand All @@ -144,12 +132,11 @@ public QueryIndex(String field, QueryIndexType type, boolean asc, String name) {
* @param type Index type.
*/
public QueryIndex(Collection<String> fields, QueryIndexType type) {
this.fields = new LinkedHashMap<>();
inlineSize = DFLT_INLINE_SIZE;
this.type = type;

for (String field : fields)
this.fields.put(field, true);

this.type = type;
addField(field, true);
}

/**
Expand All @@ -160,8 +147,10 @@ public QueryIndex(Collection<String> fields, QueryIndexType type) {
* @param type Index type.
*/
public QueryIndex(LinkedHashMap<String, Boolean> fields, QueryIndexType type) {
this.fields = fields;
inlineSize = DFLT_INLINE_SIZE;
this.type = type;

this.fields = fields;
}

/**
Expand Down Expand Up @@ -225,7 +214,7 @@ public QueryIndex setFieldNames(Collection<String> fields, boolean asc) {
this.fields = new LinkedHashMap<>();

for (String field : fields)
this.fields.put(field, asc);
addField(field, asc);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.cache.query.QueryIndexMessage;
import org.apache.ignite.internal.cache.query.index.IndexQueryResultMeta;
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition;
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
Expand Down Expand Up @@ -312,7 +313,11 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls
init(schemaAwareMarsh, resolvedClsLdr);
}

/** The order is important. If wish to remove a message, put 'msgIdx++' on its place. */
/**
* Registers all the messages into {@code factory}.
* The listing order is important here. If wish to remove a message, put 'msgIdx++' on its place. If wish to add,
* put it to end of a group.
*/
@Override public void registerAll(MessageFactory factory) {
assert this.factory == null;

Expand Down Expand Up @@ -532,6 +537,7 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls
withNoSchema(SchemaProposeDiscoveryMessage.class);
withNoSchema(SchemaFinishDiscoveryMessage.class);
withNoSchema(QueryField.class);
withNoSchema(QueryIndexMessage.class);
withNoSchema(GridCacheSqlQuery.class);
withSchema(GridCacheQueryRequest.class);
withSchema(GridCacheQueryResponse.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.cache.query;

import java.util.LinkedHashMap;
import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.cache.QueryIndexType;
import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.plugin.extensions.communication.Message;

/** Message for {@link QueryIndex}. */
public class QueryIndexMessage implements Message {
/** Index name. */
@Order(0)
public String name;

/** */
@GridToStringInclude
@Order(1)
public LinkedHashMap<String, Boolean> fields;

/** */
@Order(2)
public QueryIndexType type;

/** */
@Order(3)
public int inlineSize;

/** */
protected void addField(String fld, boolean ack) {
if (fields == null)
fields = new LinkedHashMap<>();

fields.put(fld, ack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ private void processFailedMessage(UUID nodeId,

break;

case 10910: {
case 10911: {
GridCacheQueryRequest req = (GridCacheQueryRequest)msg;

GridCacheQueryResponse res = new GridCacheQueryResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@
package org.apache.ignite.internal.processors.query.schema.operation;

import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.internal.MarshallableMessage;
import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.processors.query.QueryUtils;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;

/**
* Schema index create operation.
*/
public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation implements MarshallableMessage {
public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation {
/** */
private static final long serialVersionUID = 0L;

Expand All @@ -41,11 +37,8 @@ public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation imp

/** Index. */
@GridToStringInclude
private QueryIndex idx;

/** Serialized form of 'query index'. */
@Order(1)
transient byte[] qryIdxBytes;
QueryIndex idx;

/** Ignore operation if index exists. */
@Order(2)
Expand Down Expand Up @@ -114,21 +107,6 @@ public int parallel() {
return parallel;
}

/** {@inheritDoc} */
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
if (idx != null)
qryIdxBytes = U.marshal(marsh, idx);
}

/** {@inheritDoc} */
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException {
if (qryIdxBytes != null) {
idx = U.unmarshal(marsh, qryIdxBytes, clsLdr);

qryIdxBytes = null;
}
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(SchemaIndexCreateOperation.class, this, "parent", super.toString());
Expand Down
Loading