throw new UnsupportedException(
"When you have specified the pk, you'd better not to specify additional filter conditions.");
}
}
Action action = null;
DQLPlan qp = null;
Condition entityGroupKeyCondition = queryInfo.getField(table
.getEntityGroupKey().getName());
if (queryInfo.getType() == QueryInfo.QueryType.GET) {
byte[] primaryKey = RowBuilder.build().genRowkey(primaryKeyPairs);
// check if the column is table's primary key.
action = new GetAction(context.getReadModel(), table.getTableName(),
primaryKey, this.buildEntityColumnsForGet(table, metaEventOperation,
selectItem));
((GetAction)action).setForUpdate(queryInfo.isForUpdate());
if (context.isGenWholePlan()) {
// get entityGroupLocation according to entity group key.
EntityGroupLocation entityGroupLocation = this.connection
.locateEntityGroup(Bytes.toBytes(table.getTableName()), DruidParser
.convert(
table.getColumn(entityGroupKeyCondition.getFieldName()),
entityGroupKeyCondition.getValue()));
action.setEntityGroupLocation(entityGroupLocation);
}
qp = new LocalQueryPlan((GetAction) action);
LOG.debug(QueryInfo.QueryType.GET + " "
+ Bytes.toStringBinary(primaryKey) + " from " + table.getTableName());
} else if (queryInfo.getType() == QueryInfo.QueryType.SCAN) {
Index index = metaEventOperation.checkAndGetIndex(table,
queryInfo.getAllConditionFieldName());
if (index == null) {
throw new UnsupportedException("Don't get a Index!");
}
boolean isJustUseIndex = index.getIndexKeys().size() >= queryInfo.getAllConditionFieldName().size();
Pair<byte[], byte[]> startKeyAndEndKey = metaEventOperation.getStartkeyAndEndkey(index, queryInfo);
Pair<List<ColumnStruct>, List<ColumnStruct>> columnActionPair = this
.buildEntityColumnsForScan(table, index, metaEventOperation,
selectItem);
List<ColumnStruct> selectEntityColumns = columnActionPair.getFirst();
List<ColumnStruct> selectStoringColumns = columnActionPair.getSecond();
List<ColumnStruct> conditionNotInIndex = isJustUseIndex ? Collections.<ColumnStruct>emptyList()
: buildColumnsNotInIndex(table, index, queryInfo);
// instance scan action.
action = new ScanAction(context.getReadModel(),
StorageTableNameBuilder.buildIndexTableName(index),
table.getTableName(), startKeyAndEndKey.getFirst(),
startKeyAndEndKey.getSecond(), selectEntityColumns);
((ScanAction) action).setStoringColumns(selectStoringColumns);
((ScanAction) action).setLimit(limit);
((ScanAction) action).setNotIndexConditionColumns(conditionNotInIndex);
if (entityGroupKeyCondition != null
&& entityGroupKeyCondition.getType() == ConditionType.EQUAL) {
if (context.isGenWholePlan()) {
EntityGroupLocation entityGroupLocation = this.connection
.locateEntityGroup(Bytes.toBytes(table.getTableName()),
DruidParser.convert(
table.getColumn(entityGroupKeyCondition.getFieldName()),
entityGroupKeyCondition.getValue()));
action.setEntityGroupLocation(entityGroupLocation);
}
qp = new LocalQueryPlan((ScanAction) action);
LOG.debug(QueryInfo.QueryType.SCAN + " startKey "
+ Bytes.toStringBinary(startKeyAndEndKey.getFirst()) + " endKey "
+ Bytes.toStringBinary(startKeyAndEndKey.getSecond()));