Skip to content
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,71 @@
/*
* 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;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;

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

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

Check warning on line 37 in modules/core/src/main/java/org/apache/ignite/internal/cache/query/QueryIndexMessage.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

The type of "fields" should be an interface such as "Map" rather than the implementation "LinkedHashMap".

See more on https://sonarcloud.io/project/issues?id=apache_ignite&issues=AZ2xFsWfXHF-1chzADRs&open=AZ2xFsWfXHF-1chzADRs&pullRequest=13058

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

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

/** Empty constructor for {@link MessageFactory}. */
public QueryIndexMessage() {
// No-op.
}

/** Copies {@code idx}. */
public QueryIndexMessage(QueryIndex idx) {
name = idx.getName();
fields = idx.getFields();
type = idx.getIndexType();
inlineSize = idx.getInlineSize();
}

/** @return Copy of {@code msg} as {@link QueryIndex}. */
public static QueryIndex queryIndex(QueryIndexMessage msg) {
QueryIndex res = new QueryIndex();

res.setName(msg.name);
res.setFields(msg.fields);
res.setIndexType(msg.type);
res.setInlineSize(msg.inlineSize);

return res;
}
}
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: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vladsz83 @anton-vinogradov , now it looks very ugly that we need to do this. It is necessary to refactor this case block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use smth. like msgFactory.messageType(msg). Looks like other ticket. Or I could place the message below in the registration list. But I could place it where it should be and make a fix.

GridCacheQueryRequest req = (GridCacheQueryRequest)msg;

GridCacheQueryResponse res = new GridCacheQueryResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,33 +227,43 @@
* @return Index name.
*/
public static String indexName(String tblName, QueryIndex idx) {
String res = idx.getName();
return indexName(tblName, idx.getName(), idx.getFields());
}

if (res == null) {
StringBuilder idxName = new StringBuilder(tblName + "_");
/**
* Get index name.
*
* @param tblName Table name.
* @param idxName Index name.
* @param fields Fields.
* @return Index name.
*/
public static String indexName(String tblName, @Nullable String idxName, Map<String, Boolean> fields) {
if (idxName == null) {
StringBuilder idxName0 = new StringBuilder(tblName + "_");

for (Map.Entry<String, Boolean> field : idx.getFields().entrySet()) {
idxName.append(field.getKey());
for (Map.Entry<String, Boolean> field : fields.entrySet()) {
idxName0.append(field.getKey());

idxName.append('_');
idxName.append(field.getValue() ? "asc_" : "desc_");
idxName0.append('_');
idxName0.append(field.getValue() ? "asc_" : "desc_");

Check warning on line 249 in modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a primitive boolean expression here.

See more on https://sonarcloud.io/project/issues?id=apache_ignite&issues=AZ2xFsWVXHF-1chzADRr&open=AZ2xFsWVXHF-1chzADRr&pullRequest=13058
}

for (int i = 0; i < idxName.length(); i++) {
char ch = idxName.charAt(i);
for (int i = 0; i < idxName0.length(); i++) {
char ch = idxName0.charAt(i);

if (Character.isWhitespace(ch))
idxName.setCharAt(i, '_');
idxName0.setCharAt(i, '_');
else
idxName.setCharAt(i, Character.toLowerCase(ch));
idxName0.setCharAt(i, Character.toLowerCase(ch));
}

idxName.append("idx");
idxName0.append("idx");

return idxName.toString();
return idxName0.toString();
}

return res;
return idxName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@
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.cache.query.QueryIndexMessage;
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 +38,8 @@

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

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

Check failure on line 42 in modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make non-static "idxMsg" transient or serializable.

See more on https://sonarcloud.io/project/issues?id=apache_ignite&issues=AZ2xFsRTXHF-1chzADRq&open=AZ2xFsRTXHF-1chzADRq&pullRequest=13058

/** Ignore operation if index exists. */
@Order(2)
Expand Down Expand Up @@ -74,14 +68,14 @@
super(opId, cacheName, schemaName);

this.tblName = tblName;
this.idx = idx;
this.idxMsg = new QueryIndexMessage(idx);
this.ifNotExists = ifNotExists;
this.parallel = parallel;
}

/** {@inheritDoc} */
@Override public String indexName() {
return QueryUtils.indexName(tblName, idx);
return QueryUtils.indexName(tblName, idxMsg.name, idxMsg.fields);
}

/**
Expand All @@ -95,7 +89,7 @@
* @return Index params.
*/
public QueryIndex index() {
return idx;
return QueryIndexMessage.queryIndex(idxMsg);
}

/**
Expand All @@ -114,21 +108,6 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@
package org.apache.ignite.internal.codegen;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.processing.Processor;
import javax.tools.JavaFileObject;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.Compiler;
import com.google.testing.compile.JavaFileObjects;
import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.cache.QueryIndexType;
import org.apache.ignite.internal.MessageProcessor;
import org.apache.ignite.internal.Order;
import org.apache.ignite.internal.cache.query.QueryIndexMessage;
import org.apache.ignite.internal.util.CommonUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteUuid;
Expand Down Expand Up @@ -165,6 +172,34 @@ public void testPojoFieldFailed() {
assertThat(compilation).failed();
}

/** Tests the messages that copy a data/classes. */
@Test
public void testCopies() {
Field[] fields0 = QueryIndex.class.getDeclaredFields();

Map<String, Field> fields = CommonUtils.newHashMap(fields0.length);

for (Field f : fields0) {
if (!Modifier.isStatic(f.getModifiers()))
fields.put(f.getName(), f);
}

assertEquals(4, fields.size());

assertEquals(String.class, fields.get("name").getType());
assertEquals(LinkedHashMap.class, fields.get("fields").getType());
assertEquals(QueryIndexType.class, fields.get("type").getType());
assertEquals(int.class, fields.get("inlineSize").getType());

QueryIndex idx = new QueryIndex("fld0", QueryIndexType.GEOSPATIAL, false, "testIdx");

QueryIndexMessage msg = new QueryIndexMessage(idx);

QueryIndex idx1 = QueryIndexMessage.queryIndex(msg);

assertEquals(idx, idx1);
}

/** */
@Test
public void testExceptionFailed() {
Expand Down
Loading