Skip to content
Open
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 @@ -309,9 +309,10 @@ private void handle0(AlterTableDropCommand cmd) throws IgniteCheckedException {

/** */
private QueryEntity toQueryEntity(CreateTableCommand cmd) {
QueryEntity res = new QueryEntity();
QueryEntityEx res = new QueryEntityEx();

res.setTableName(cmd.tableName());
res.sql(true);

Set<String> notNullFields = null;

Expand Down Expand Up @@ -369,7 +370,7 @@ private QueryEntity toQueryEntity(CreateTableCommand cmd) {
if (!F.isEmpty(cmd.primaryKeyColumns())) {
res.setKeyFields(new LinkedHashSet<>(cmd.primaryKeyColumns()));

res = new QueryEntityEx(res).setPreserveKeysOrder(true);
res.setPreserveKeysOrder(true);
}
}
else if (!F.isEmpty(cmd.primaryKeyColumns()) && cmd.primaryKeyColumns().size() == 1) {
Expand All @@ -383,19 +384,14 @@ else if (!F.isEmpty(cmd.primaryKeyColumns()) && cmd.primaryKeyColumns().size() =
// if pk is not explicitly set, we create it ourselves
keyTypeName = IgniteUuid.class.getName();

res = new QueryEntityEx(res).implicitPk(true);
res.implicitPk(true);
}

res.setValueType(F.isEmpty(cmd.valueTypeName()) ? valTypeName : cmd.valueTypeName());
res.setKeyType(keyTypeName);

if (!F.isEmpty(notNullFields)) {
QueryEntityEx res0 = new QueryEntityEx(res);

res0.setNotNullFields(notNullFields);

res = res0;
}
if (!F.isEmpty(notNullFields))
res.setNotNullFields(notNullFields);

return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public GridCursor<IndexRow> find(
* Finds first index row for specified tree segment and cache filter.
*
* @param segment Number of tree segment to find.
* @param qryCtx External index qyery context.
* @param qryCtx External index query context.
* @return Cursor of found index rows.
*/
public GridCursor<IndexRow> findFirst(int segment, IndexQueryContext qryCtx)
Expand All @@ -79,7 +79,7 @@ public GridCursor<IndexRow> findFirst(int segment, IndexQueryContext qryCtx)
* Finds last index row for specified tree segment and cache filter.
*
* @param segment Number of tree segment to find.
* @param qryCtx External index qyery context.
* @param qryCtx External index query context.
* @return Cursor of found index rows.
*/
public GridCursor<IndexRow> findLast(int segment, IndexQueryContext qryCtx)
Expand All @@ -88,7 +88,7 @@ public GridCursor<IndexRow> findLast(int segment, IndexQueryContext qryCtx)
/**
* Takes only one first or last index record.
*
* @param qryCtx External index qyery context.
* @param qryCtx External index query context.
* @param first {@code True} to take first index value. {@code False} to take last index value.
*/
public GridCursor<IndexRow> findFirstOrLast(IndexQueryContext qryCtx, boolean first) throws IgniteCheckedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ public interface GridQueryTypeDescriptor {
*/
public void implicitPk(boolean implicitPk);

/**
* Gets whether a type was created by SQL.
*
* NOTE: There is a difference between query type descriptor sql flag and cache descriptor sql flag. The same flag
* on cache descriptor specifies whether entire cache was created by sql, but query type descriptor sql flag can
* be set to true even when cache sql flag is false (for example, when cache was created by cache API,
* but query type was added by SQL).
*/
public boolean sql();

/**
* Sets whether a type was created by DDL.
*
* @param sql Whether a type was created by SQL.
*/
public void sql(boolean sql);

/**
* @return {@code true} if absent PK parts should be filled with defaults, {@code false} otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class QueryEntityEx extends QueryEntity {
/** INLINE_SIZE for affinity field index. */
private Integer affKeyInlineSize;

/** Whether query entity was created by SQL. */
private boolean sql;

/**
* Default constructor.
*/
Expand Down Expand Up @@ -77,6 +80,7 @@ public QueryEntityEx(QueryEntity other) {
fillAbsentPKsWithDefaults = other0.fillAbsentPKsWithDefaults;
pkInlineSize = other0.pkInlineSize != null ? other0.pkInlineSize : -1;
affKeyInlineSize = other0.affKeyInlineSize != null ? other0.affKeyInlineSize : -1;
sql = other0.sql;
}
}

Expand Down Expand Up @@ -121,6 +125,18 @@ public QueryEntity implicitPk(boolean implicitPk) {
return this;
}

/** */
public boolean sql() {
return sql;
}

/** */
public QueryEntityEx sql(boolean sql) {
this.sql = sql;

return this;
}

/**
* @return {@code true} if absent PK parts should be filled with defaults, {@code false} otherwise.
*/
Expand Down Expand Up @@ -204,7 +220,8 @@ public QueryEntity setAffinityKeyInlineSize(Integer affKeyInlineSize) {
&& preserveKeysOrder == entity.preserveKeysOrder
&& implicitPk == entity.implicitPk
&& Objects.equals(pkInlineSize, entity.pkInlineSize)
&& Objects.equals(affKeyInlineSize, entity.affKeyInlineSize);
&& Objects.equals(affKeyInlineSize, entity.affKeyInlineSize)
&& sql == entity.sql;
}

/** {@inheritDoc} */
Expand All @@ -216,6 +233,7 @@ public QueryEntity setAffinityKeyInlineSize(Integer affKeyInlineSize) {
res = 31 * res + (implicitPk ? 1 : 0);
res = 31 * res + (pkInlineSize != null ? pkInlineSize.hashCode() : 0);
res = 31 * res + (affKeyInlineSize != null ? affKeyInlineSize.hashCode() : 0);
res = 31 * res + (sql ? 1 : 0);
return res;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
/** @see SqlConfiguration#isValidationEnabled() */
private final boolean validateTypes;

/** */
private boolean sql;

/**
* Constructor.
*
Expand Down Expand Up @@ -834,6 +837,16 @@ else if (cacheObjects.typeId(expColType.getName()) != ((BinaryObject)val).type()
this.implicitPk = implicitPk;
}

/** {@inheritDoc} */
@Override public boolean sql() {
return sql;
}

/** {@inheritDoc} */
@Override public void sql(boolean sql) {
this.sql = sql;
}

/** {@inheritDoc} */
@Override public boolean fillAbsentPKsWithDefaults() {
return fillAbsentPKsWithDefaults;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ public static QueryTypeCandidate typeForQueryEntity(GridKernalContext ctx, Strin

desc.primaryKeyInlineSize(qe.getPrimaryKeyInlineSize() != null ? qe.getPrimaryKeyInlineSize() : -1);
desc.affinityFieldInlineSize(qe.getAffinityKeyInlineSize() != null ? qe.getAffinityKeyInlineSize() : -1);
desc.sql(qe.sql());
}
else {
desc.primaryKeyInlineSize(-1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class TableDescriptor {
public TableDescriptor(GridCacheContextInfo<?, ?> cacheInfo, GridQueryTypeDescriptor typeDesc, boolean isSql) {
this.cacheInfo = cacheInfo;
this.typeDesc = typeDesc;
this.isSql = isSql;
this.isSql = isSql || typeDesc.sql();
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.

probably it will be better to move sql flag into QueryTypeCandidate and reduce such spaghetti code ?

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.

Do you mean QueryTypeCandidate instead of QueryEntityEx? QueryTypeCandidate - it's an runtime entity, it's not stored to PDS and don't used in DynamicCacheDescriptor to pass to other nodes.


if (F.isEmpty(typeDesc.affinityKey()) || Objects.equals(typeDesc.affinityKey(), typeDesc.keyFieldName()))
affKey = QueryUtils.KEY_FIELD_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ private static QueryEntity toQueryEntity(GridSqlCreateTable createTbl) {
QueryEntityEx res = new QueryEntityEx();

res.setTableName(createTbl.tableName());
res.sql(true);

Set<String> notNullFields = null;

Expand Down
Loading
Loading