Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-5420 #2093

Closed
wants to merge 4 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.cache.QueryIndex;
Expand Down Expand Up @@ -288,15 +290,29 @@ private static QueryEntity toQueryEntity(GridSqlCreateTable createTbl) {
res.addQueryField(e.getKey(), DataType.getTypeClassName(col.getType()), null);
}

res.setKeyType(createTbl.tableName() + "Key");
String valTypeName = valueType(createTbl.schemaName(), createTbl.tableName());
String keyTypeName = valTypeName + "_Key";

res.setValueType(createTbl.tableName());
res.setValueType(valTypeName);
res.setKeyType(keyTypeName);

res.setKeyFields(createTbl.primaryKeyColumns());

return res;
}

/**
* Construct value type name for table.
*
* @param schemaName Schema name.
* @param tblName Table name.
* @return Value type name.
*/
private static String valueType(String schemaName, String tblName) {
return "sql_" + schemaName + "_" + tblName + "_" + UUID.randomUUID().toString().replace("-", "_");
}


/**
* @param cmd Statement.
* @return Whether {@code cmd} is a DDL statement we're able to handle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import javax.cache.CacheException;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
Expand All @@ -51,7 +49,6 @@
import org.apache.ignite.internal.processors.query.h2.opt.GridH2Table;
import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.testframework.GridTestUtils;

/**
Expand Down Expand Up @@ -191,26 +188,22 @@ private void doTestCreateTable(String tplCacheName, CacheMode mode) {
QueryTypeDescriptorImpl desc = typeExisting(node, "Person", "Person");

assertEquals(Object.class, desc.keyClass());

assertEquals("PersonKey", desc.keyTypeName());

assertEquals(Object.class, desc.valueClass());

assertEquals("Person", desc.valueTypeName());
assertTrue(desc.valueTypeName(), desc.valueTypeName().contains("Person"));

assertTrue(desc.keyTypeName(), desc.keyTypeName().startsWith(desc.valueTypeName()));
assertTrue(desc.keyTypeName(), desc.keyTypeName().endsWith("Key"));

assertEquals(
F.asList("id", "city", "name", "surname", "age"),
new ArrayList<>(desc.fields().keySet())
);

assertProperty(desc, "id", Integer.class, true);

assertProperty(desc, "city", String.class, true);

assertProperty(desc, "name", String.class, false);

assertProperty(desc, "surname", String.class, false);

assertProperty(desc, "age", Integer.class, false);

GridH2Table tbl = ((IgniteH2Indexing)node.context().query().getIndexing()).dataTable("PUBLIC", "Person");
Expand Down Expand Up @@ -465,6 +458,7 @@ public void testCreateTableInNonPublicSchema() throws Exception {
* @param params Engine parameters.
* @param expErrMsg Expected error message.
*/
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void assertCreateTableWithParamsThrows(final String params, String expErrMsg) {
GridTestUtils.assertThrows(null, new Callable<Object>() {
@Override public Object call() throws Exception {
Expand Down Expand Up @@ -587,13 +581,6 @@ private IgniteEx client() {
return grid(CLIENT);
}

/**
* @return Cache to issue queries upon.
*/
private IgniteCache<?, ?> cache() {
return client().cache(INDEXED_CACHE_NAME);
}

/**
* @return Default cache configuration.
*/
Expand Down