Ildar Absalyamov has uploaded a new change for review.
https://asterix-gerrit.ics.uci.edu/712
Change subject: Reapply fix for ASTERIXDB-1109 on merged master
......................................................................
Reapply fix for ASTERIXDB-1109 on merged master
Change-Id: I8fcf41c009f9faf51bc8bccc0c3c7217b7769121
---
M
asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceMaterializationForInsertWithSelfScanRule.java
M
asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
M
asterix-algebra/src/main/java/org/apache/asterix/translator/CompiledStatements.java
M
asterix-app/src/main/java/org/apache/asterix/aql/translator/QueryTranslator.java
M
asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-2.plan
R
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-collision/index-type-collision.1.ddl.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-promotion-collision/index-type-promotion-collision.1.ddl.aql
R
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/record-type-collision/record-collision.1.ddl.aql
A
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.ddl.aql
A
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.update.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.3.ddl.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.4.query.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.5.ddl.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.6.query.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.1.ddl.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.2.update.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.3.ddl.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.4.query.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.5.query.aql
C
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.6.query.aql
A
asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.adm
A
asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.adm
A
asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.1.adm
A
asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.2.adm
A
asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.3.adm
M asterix-app/src/test/resources/runtimets/testsuite.xml
26 files changed, 468 insertions(+), 278 deletions(-)
git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb
refs/changes/12/712/1
diff --git
a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceMaterializationForInsertWithSelfScanRule.java
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceMaterializationForInsertWithSelfScanRule.java
index 916355d..318db3b 100644
---
a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceMaterializationForInsertWithSelfScanRule.java
+++
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceMaterializationForInsertWithSelfScanRule.java
@@ -42,6 +42,7 @@
import
org.apache.hyracks.algebricks.core.algebra.operators.physical.MaterializePOperator;
import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
+// TODO: Reconsider if materialization is needed in delete pipeline
public class IntroduceMaterializationForInsertWithSelfScanRule implements
IAlgebraicRewriteRule {
@Override
diff --git
a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
index 956e6c5..d7f726b 100644
---
a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
+++
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceSecondaryIndexInsertDeleteRule.java
@@ -22,7 +22,10 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Set;
import java.util.Stack;
import org.apache.asterix.common.config.DatasetConfig.DatasetType;
@@ -48,10 +51,13 @@
import org.apache.asterix.om.types.AUnionType;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.asterix.om.types.IAType;
+import org.apache.asterix.om.types.hierachy.ATypeHierarchy;
import org.apache.asterix.om.util.NonTaggedFormatUtil;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.mutable.Mutable;
import org.apache.commons.lang3.mutable.MutableObject;
+import org.apache.hadoop.hive.ql.exec.FunctionUtils;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.common.utils.Pair;
import org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression;
@@ -102,9 +108,12 @@
/** find the record variable */
InsertDeleteUpsertOperator insertOp = (InsertDeleteUpsertOperator) op1;
ILogicalExpression recordExpr =
insertOp.getPayloadExpression().getValue();
- List<LogicalVariable> recordVar = new ArrayList<LogicalVariable>();
+ LogicalVariable recordVar = null;
+ List<LogicalVariable> usedRecordVars = new ArrayList<>();
/** assume the payload is always a single variable expression */
- recordExpr.getUsedVariables(recordVar);
+ recordExpr.getUsedVariables(usedRecordVars);
+ if (usedRecordVars.size() == 1)
+ recordVar = usedRecordVars.get(0);
/**
* op2 is the assign operator which extract primary keys from the
record
@@ -112,7 +121,7 @@
*/
AbstractLogicalOperator op2 = (AbstractLogicalOperator)
op1.getInputs().get(0).getValue();
- if (recordVar.size() == 0) {
+ if (recordVar == null) {
/**
* For the case primary key-assignment expressions are constant
* expressions, find assign op that creates record to be
@@ -135,7 +144,7 @@
}
}
AssignOperator assignOp2 = (AssignOperator) op2;
- recordVar.addAll(assignOp2.getVariables());
+ recordVar = assignOp2.getVariables().get(0);
}
/*
@@ -197,10 +206,65 @@
op0.getInputs().clear();
}
- // Replicate Operator is applied only when doing the bulk-load.
- ReplicateOperator replicateOp = null;
+ // Prepare filtering field information
+ List<String> filteringFields = ((InternalDatasetDetails)
dataset.getDatasetDetails()).getFilterField();
+ List<LogicalVariable> filteringVars = null;
+ List<Mutable<ILogicalExpression>> filteringAssignExpressions = null;
+ List<Mutable<ILogicalExpression>> filteringExpressions = null;
+ AssignOperator filteringAssign = null;
- // No need to take care of the upsert case in the bulk load since it
doesn't exist as of now
+ if (filteringFields != null) {
+ filteringVars = new ArrayList<LogicalVariable>();
+ filteringAssignExpressions = new
ArrayList<Mutable<ILogicalExpression>>();
+ filteringExpressions = new
ArrayList<Mutable<ILogicalExpression>>();
+ prepareVarAndExpression(filteringFields, recType.getFieldNames(),
recordVar,
+ filteringAssignExpressions, filteringVars, context);
+ filteringAssign = new AssignOperator(filteringVars,
+ filteringAssignExpressions);
+ for (LogicalVariable var : filteringVars) {
+ filteringExpressions.add(new MutableObject<ILogicalExpression>(
+ new VariableReferenceExpression(var)));
+ }
+ }
+ LogicalVariable enforcedRecordVar = recordVar;
+
+ if (insertOp.getOperation() == Kind.INSERT) {
+ try {
+ DatasetDataSource ds = (DatasetDataSource)
(insertOp.getDataSource());
+ ARecordType insertRecType = (ARecordType)
ds.getSchemaTypes()[ds.getSchemaTypes().length - 1];
+ LogicalVariable castVar = context.newVar();
+ ARecordType enforcedType = createEnforcedType(insertRecType,
indexes);
+ if (!enforcedType.equals(insertRecType)) {
+ //introduce casting to enforced type
+ AbstractFunctionCallExpression castFunc = new
ScalarFunctionCallExpression(
+
FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.CAST_RECORD));
+
+ castFunc.getArguments().add(
+ new
MutableObject<ILogicalExpression>(insertOp.getPayloadExpression().getValue()));
+ TypeComputerUtilities.setRequiredAndInputTypes(castFunc,
enforcedType, insertRecType);
+ AssignOperator castedRecordAssignOperator = new
AssignOperator(castVar,
+ new MutableObject<ILogicalExpression>(castFunc));
+ castedRecordAssignOperator.getInputs().add(new
MutableObject<ILogicalOperator>(currentTop));
+ currentTop = castedRecordAssignOperator;
+ enforcedRecordVar = castVar;
+ recType = enforcedType;
+
context.computeAndSetTypeEnvironmentForOperator(castedRecordAssignOperator);
+ }
+ } catch (AsterixException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ Set<LogicalVariable> projectVars = new HashSet<LogicalVariable>();
+ VariableUtilities.getUsedVariables(op1, projectVars);
+ if (enforcedRecordVar != null)
+ projectVars.add(enforcedRecordVar);
+ ProjectOperator project = new ProjectOperator(new
ArrayList<LogicalVariable>(projectVars));
+ project.getInputs().add(new
MutableObject<ILogicalOperator>(currentTop));
+ context.computeAndSetTypeEnvironmentForOperator(project);
+ currentTop = project;
+
+ // Replicate Operator is applied only when doing the bulk-load.
+ AbstractLogicalOperator replicateOp = null;
if (secondaryIndexTotalCnt > 1 && insertOp.isBulkload()) {
// Split the logical plan into "each secondary index update branch"
// to replicate each <PK,RECORD> pair.
@@ -211,76 +275,13 @@
currentTop = replicateOp;
}
- // Prepare filtering field information (This is the filter created
using the "filter with" key word in the
- // create dataset ddl)
- List<String> filteringFields = ((InternalDatasetDetails)
dataset.getDatasetDetails()).getFilterField();
- List<LogicalVariable> filteringVars = null;
- List<Mutable<ILogicalExpression>> filteringExpressions = null;
-
- if (filteringFields != null) {
- // The filter field var already exists. we can simply get it from
the insert op
- filteringVars = new ArrayList<LogicalVariable>();
- filteringExpressions = new
ArrayList<Mutable<ILogicalExpression>>();
- for (Mutable<ILogicalExpression> filteringExpression :
insertOp.getAdditionalFilteringExpressions()) {
- filteringExpression.getValue().getUsedVariables(filteringVars);
- for (LogicalVariable var : filteringVars) {
- filteringExpressions
- .add(new MutableObject<ILogicalExpression>(new
VariableReferenceExpression(var)));
- }
- }
- }
-
// Iterate each secondary index and applying Index Update operations.
- // At first, op1 is the index insert op insertOp
for (Index index : indexes) {
- List<LogicalVariable> projectVars = new
ArrayList<LogicalVariable>();
- // Q. Why do we add these used variables to the projectVars?
- // A. We want to always keep the primary keys, the record, and the
filtering values
- // In addition to those, we want to extract and keep the secondary
key
- VariableUtilities.getUsedVariables(insertOp, projectVars);
if (!index.isSecondaryIndex()) {
continue;
}
- LogicalVariable enforcedRecordVar = recordVar.get(0);
hasSecondaryIndex = true;
- /*
- * if the index is enforcing field types (For open indexes), We
add a cast
- * operator to ensure type safety
- */
- if (index.isEnforcingKeyFileds()) {
- try {
- DatasetDataSource ds = (DatasetDataSource)
(insertOp.getDataSource());
- ARecordType insertRecType = (ARecordType)
ds.getSchemaTypes()[ds.getSchemaTypes().length - 1];
- // A new variable which represents the casted record
- LogicalVariable castVar = context.newVar();
- // create the expected record type = the original + the
optional open field
- ARecordType enforcedType =
createEnforcedType(insertRecType, index);
- // introduce casting to enforced type
- AbstractFunctionCallExpression castFunc = new
ScalarFunctionCallExpression(
-
FunctionUtil.getFunctionInfo(AsterixBuiltinFunctions.CAST_RECORD));
- // The first argument is the record
- castFunc.getArguments()
- .add(new
MutableObject<ILogicalExpression>(insertOp.getPayloadExpression().getValue()));
- TypeComputerUtilities.setRequiredAndInputTypes(castFunc,
enforcedType, insertRecType);
- // AssignOperator puts in the cast var the casted record
- AssignOperator newAssignOperator = new
AssignOperator(castVar,
- new MutableObject<ILogicalExpression>(castFunc));
- // Connect the current top of the plan to the cast operator
- newAssignOperator.getInputs().add(new
MutableObject<ILogicalOperator>(currentTop));
- currentTop = newAssignOperator;
- projectVars.add(castVar);
- enforcedRecordVar = castVar;
-
context.computeAndSetTypeEnvironmentForOperator(newAssignOperator);
-
context.computeAndSetTypeEnvironmentForOperator(currentTop);
- recType = enforcedType;
- // We don't need to cast the old rec, we just need an
assignment function that extracts the SK
- // and an expression which reference the new variables.
- } catch (AsterixException e) {
- throw new AlgebricksException(e);
- }
- }
- // Get the secondary fields names and types
List<List<String>> secondaryKeyFields = index.getKeyFieldNames();
List<IAType> secondaryKeyTypes = index.getKeyFieldTypes();
List<LogicalVariable> secondaryKeyVars = new
ArrayList<LogicalVariable>();
@@ -308,9 +309,8 @@
prevSecondaryKeyAssign = new
AssignOperator(prevSecondaryKeyVars, prevExpressions);
}
AssignOperator assign = new AssignOperator(secondaryKeyVars,
expressions);
- ProjectOperator project = new ProjectOperator(projectVars);
+
AssignOperator topAssign = assign;
- assign.getInputs().add(new
MutableObject<ILogicalOperator>(project));
if (insertOp.getOperation() == Kind.UPSERT) {
projectVars.add(insertOp.getPrevRecordVar());
if (filteringFields != null) {
@@ -321,13 +321,11 @@
topAssign = prevSecondaryKeyAssign;
}
// Only apply replicate operator when doing bulk-load
- if (secondaryIndexTotalCnt > 1 && insertOp.isBulkload()) {
- project.getInputs().add(new
MutableObject<ILogicalOperator>(replicateOp));
- } else {
- project.getInputs().add(new
MutableObject<ILogicalOperator>(currentTop));
- }
-
- context.computeAndSetTypeEnvironmentForOperator(project);
+ if (secondaryIndexTotalCnt > 1 && insertOp.isBulkload())
+ topAssign.getInputs().add(new
MutableObject<ILogicalOperator>(replicateOp));
+ else
+ topAssign.getInputs().add(new
MutableObject<ILogicalOperator>(currentTop));
+
context.computeAndSetTypeEnvironmentForOperator(assign);
if (insertOp.getOperation() == Kind.UPSERT) {
context.computeAndSetTypeEnvironmentForOperator(prevSecondaryKeyAssign);
@@ -406,7 +404,8 @@
// TokenizeOperator to tokenize [SK, PK] pairs
TokenizeOperator tokenUpdate = new
TokenizeOperator(dataSourceIndex,
insertOp.getPrimaryKeyExpressions(),
secondaryExpressions, tokenizeKeyVars,
- filterExpression, insertOp.getOperation(),
insertOp.isBulkload(), isPartitioned, varTypes);
+ filterExpression, insertOp.getOperation(),
insertOp.isBulkload(), isPartitioned,
+ varTypes);
tokenUpdate.getInputs().add(new
MutableObject<ILogicalOperator>(assign));
context.computeAndSetTypeEnvironmentForOperator(tokenUpdate);
@@ -554,71 +553,98 @@
return true;
}
- public static ARecordType createEnforcedType(ARecordType initialType,
Index index)
+ // Merges typed index fields with specified recordType, allowing indexed
fields to be optional.
+ // I.e. the type { "personId":int32, "name": string, "address" : {
"street": string } } with typed indexes on age:int32, address.state:string
+ // will be merged into type { "personId":int32, "name": string,
"age": int32? "address" : { "street": string, "state": string? } }
+ // Used by open indexes to enforce the type of an indexed record
+ public static ARecordType createEnforcedType(ARecordType initialType,
List<Index> indexes)
throws AsterixException, AlgebricksException {
ARecordType enforcedType = initialType;
- for (int i = 0; i < index.getKeyFieldNames().size(); i++) {
- try {
- Stack<Pair<ARecordType, String>> nestedTypeStack = new
Stack<Pair<ARecordType, String>>();
- List<String> splits = index.getKeyFieldNames().get(i);
- ARecordType nestedFieldType = enforcedType;
- boolean openRecords = false;
- String bridgeName = nestedFieldType.getTypeName();
- int j;
- // Build the stack for the enforced type
- for (j = 1; j < splits.size(); j++) {
- nestedTypeStack.push(new Pair<ARecordType,
String>(nestedFieldType, splits.get(j - 1)));
- bridgeName = nestedFieldType.getTypeName();
- nestedFieldType = (ARecordType)
enforcedType.getSubFieldType(splits.subList(0, j));
- if (nestedFieldType == null) {
- openRecords = true;
- break;
+ for (Index index : indexes) {
+ if (!index.isSecondaryIndex() || !index.isEnforcingKeyFileds()) {
+ continue;
+ }
+ for (int i = 0; i < index.getKeyFieldNames().size(); i++) {
+ try {
+ Stack<Pair<ARecordType, String>> nestedTypeStack = new
Stack<Pair<ARecordType, String>>();
+ List<String> splits = index.getKeyFieldNames().get(i);
+ ARecordType nestedFieldType = enforcedType;
+ boolean openRecords = false;
+ String bridgeName = nestedFieldType.getTypeName();
+ int j;
+ //Build the stack for the enforced type
+ for (j = 1; j < splits.size(); j++) {
+ nestedTypeStack.push(new Pair<ARecordType,
String>(nestedFieldType, splits.get(j - 1)));
+ bridgeName = nestedFieldType.getTypeName();
+ nestedFieldType = (ARecordType)
enforcedType.getSubFieldType(splits.subList(0, j));
+ if (nestedFieldType == null) {
+ openRecords = true;
+ break;
+ }
}
- }
- if (openRecords == true) {
- // create the smallest record
- enforcedType = new ARecordType(splits.get(splits.size() -
2),
- new String[] { splits.get(splits.size() - 1) },
- new IAType[] {
AUnionType.createNullableType(index.getKeyFieldTypes().get(i)) }, true);
- // create the open part of the nested field
- for (int k = splits.size() - 3; k > (j - 2); k--) {
- enforcedType = new ARecordType(splits.get(k), new
String[] { splits.get(k + 1) },
- new IAType[] {
AUnionType.createNullableType(enforcedType) }, true);
+ if (openRecords == true) {
+ //create the smallest record
+ enforcedType = new
ARecordType(splits.get(splits.size() - 2),
+ new String[] { splits.get(splits.size() - 1) },
+ new IAType[] {
AUnionType.createNullableType(index.getKeyFieldTypes().get(i)) }, true);
+ //create the open part of the nested field
+ for (int k = splits.size() - 3; k > (j - 2); k--) {
+ enforcedType = new ARecordType(splits.get(k), new
String[] { splits.get(k + 1) },
+ new IAType[] {
AUnionType.createNullableType(enforcedType) }, true);
+ }
+ //Bridge the gap
+ Pair<ARecordType, String> gapPair =
nestedTypeStack.pop();
+ ARecordType parent = gapPair.first;
+
+ IAType[] parentFieldTypes =
ArrayUtils.addAll(parent.getFieldTypes().clone(),
+ new IAType[] {
AUnionType.createNullableType(enforcedType) });
+ enforcedType = new ARecordType(bridgeName,
+ ArrayUtils.addAll(parent.getFieldNames(),
enforcedType.getTypeName()), parentFieldTypes,
+ true);
+
+ } else {
+ //Schema is closed all the way to the field
+ //enforced fields are either null or strongly typed
+ LinkedHashMap<String, IAType> recordNameTypesMap = new
LinkedHashMap<String, IAType>();
+ for (j = 0; j <
nestedFieldType.getFieldNames().length; j++) {
+
recordNameTypesMap.put(nestedFieldType.getFieldNames()[j],
+ nestedFieldType.getFieldTypes()[j]);
+ }
+ // if a an enforced field already exists and the type
is correct
+ IAType enforcedFieldType =
recordNameTypesMap.get(splits.get(splits.size() - 1));
+ if (enforcedFieldType != null &&
enforcedFieldType.getTypeTag() == ATypeTag.UNION
+ && ((AUnionType)
enforcedFieldType).isNullableType())
+ enforcedFieldType = ((AUnionType)
enforcedFieldType).getNullableType();
+ if (enforcedFieldType != null &&
!ATypeHierarchy.canPromote(enforcedFieldType.getTypeTag(),
+ index.getKeyFieldTypes().get(i).getTypeTag()))
+ throw new AlgebricksException("Cannot enforce
field " + index.getKeyFieldNames().get(i)
+ + " to have type " +
index.getKeyFieldTypes().get(i));
+ if (enforcedFieldType == null)
+ recordNameTypesMap.put(splits.get(splits.size() -
1),
+
AUnionType.createNullableType(index.getKeyFieldTypes().get(i)));
+ enforcedType = new
ARecordType(nestedFieldType.getTypeName(),
+ recordNameTypesMap.keySet().toArray(new
String[recordNameTypesMap.size()]),
+ recordNameTypesMap.values().toArray(new
IAType[recordNameTypesMap.size()]),
+ nestedFieldType.isOpen());
}
- // Bridge the gap
- Pair<ARecordType, String> gapPair = nestedTypeStack.pop();
- ARecordType parent = gapPair.first;
- IAType[] parentFieldTypes =
ArrayUtils.addAll(parent.getFieldTypes().clone(),
- new IAType[] {
AUnionType.createNullableType(enforcedType) });
- enforcedType = new ARecordType(bridgeName,
- ArrayUtils.addAll(parent.getFieldNames(),
enforcedType.getTypeName()), parentFieldTypes,
- true);
-
- } else {
- // Schema is closed all the way to the field
- // enforced fields are either null or strongly typed
- enforcedType = new
ARecordType(nestedFieldType.getTypeName(),
- ArrayUtils.addAll(nestedFieldType.getFieldNames(),
splits.get(splits.size() - 1)),
- ArrayUtils.addAll(nestedFieldType.getFieldTypes(),
-
AUnionType.createNullableType(index.getKeyFieldTypes().get(i))),
- nestedFieldType.isOpen());
- }
-
- // Create the enforcedtype for the nested fields in the
schema, from the ground up
- if (nestedTypeStack.size() > 0) {
- while (!nestedTypeStack.isEmpty()) {
- Pair<ARecordType, String> nestedTypePair =
nestedTypeStack.pop();
- ARecordType nestedRecType = nestedTypePair.first;
- IAType[] nestedRecTypeFieldTypes =
nestedRecType.getFieldTypes().clone();
-
nestedRecTypeFieldTypes[nestedRecType.getFieldIndex(nestedTypePair.second)] =
enforcedType;
- enforcedType = new
ARecordType(nestedRecType.getTypeName(), nestedRecType.getFieldNames(),
- nestedRecTypeFieldTypes,
nestedRecType.isOpen());
+ //Create the enforcedtype for the nested fields in the
schema, from the ground up
+ if (nestedTypeStack.size() > 0) {
+ while (!nestedTypeStack.isEmpty()) {
+ Pair<ARecordType, String> nestedTypePair =
nestedTypeStack.pop();
+ ARecordType nestedRecType = nestedTypePair.first;
+ IAType[] nestedRecTypeFieldTypes =
nestedRecType.getFieldTypes().clone();
+ nestedRecTypeFieldTypes[nestedRecType
+ .getFieldIndex(nestedTypePair.second)] =
enforcedType;
+ enforcedType = new
ARecordType(nestedRecType.getTypeName() + "_enforced",
+ nestedRecType.getFieldNames(),
nestedRecTypeFieldTypes, nestedRecType.isOpen());
+ }
}
- }
- } catch (IOException e) {
- throw new AsterixException(e);
+ } catch (IOException e) {
+ throw new AlgebricksException(
+ "Cannot enforce typed fields " +
StringUtils.join(index.getKeyFieldNames()), e);
+ }
}
}
return enforcedType;
diff --git
a/asterix-algebra/src/main/java/org/apache/asterix/translator/CompiledStatements.java
b/asterix-algebra/src/main/java/org/apache/asterix/translator/CompiledStatements.java
index 5dc9f18..e98ab39 100644
---
a/asterix-algebra/src/main/java/org/apache/asterix/translator/CompiledStatements.java
+++
b/asterix-algebra/src/main/java/org/apache/asterix/translator/CompiledStatements.java
@@ -66,8 +66,8 @@
// added by yasser
public static class CompiledCreateDataverseStatement implements
ICompiledStatement {
- private String dataverseName;
- private String format;
+ private final String dataverseName;
+ private final String format;
public CompiledCreateDataverseStatement(String dataverseName, String
format) {
this.dataverseName = dataverseName;
@@ -89,7 +89,7 @@
}
public static class CompiledNodeGroupDropStatement implements
ICompiledStatement {
- private String nodeGroupName;
+ private final String nodeGroupName;
public CompiledNodeGroupDropStatement(String nodeGroupName) {
this.nodeGroupName = nodeGroupName;
@@ -106,9 +106,9 @@
}
public static class CompiledIndexDropStatement implements
ICompiledStatement {
- private String dataverseName;
- private String datasetName;
- private String indexName;
+ private final String dataverseName;
+ private final String datasetName;
+ private final String indexName;
public CompiledIndexDropStatement(String dataverseName, String
datasetName, String indexName) {
this.dataverseName = dataverseName;
@@ -135,8 +135,8 @@
}
public static class CompiledDataverseDropStatement implements
ICompiledStatement {
- private String dataverseName;
- private boolean ifExists;
+ private final String dataverseName;
+ private final boolean ifExists;
public CompiledDataverseDropStatement(String dataverseName, boolean
ifExists) {
this.dataverseName = dataverseName;
@@ -158,7 +158,7 @@
}
public static class CompiledTypeDropStatement implements
ICompiledStatement {
- private String typeName;
+ private final String typeName;
public CompiledTypeDropStatement(String nodeGroupName) {
this.typeName = nodeGroupName;
@@ -247,11 +247,11 @@
}
public static class CompiledLoadFromFileStatement implements
ICompiledDmlStatement {
- private String dataverseName;
- private String datasetName;
- private boolean alreadySorted;
- private String adapter;
- private Map<String, String> properties;
+ private final String dataverseName;
+ private final String datasetName;
+ private final boolean alreadySorted;
+ private final String adapter;
+ private final Map<String, String> properties;
public CompiledLoadFromFileStatement(String dataverseName, String
datasetName, String adapter,
Map<String, String> properties, boolean alreadySorted) {
@@ -340,12 +340,12 @@
}
public static class CompiledConnectFeedStatement implements
ICompiledDmlStatement {
- private String dataverseName;
- private String feedName;
- private String datasetName;
- private String policyName;
+ private final String dataverseName;
+ private final String feedName;
+ private final String datasetName;
+ private final String policyName;
private Query query;
- private int varCounter;
+ private final int varCounter;
public CompiledConnectFeedStatement(String dataverseName, String
feedName, String datasetName,
String policyName, Query query, int varCounter) {
@@ -435,9 +435,9 @@
}
public static class CompiledDisconnectFeedStatement implements
ICompiledDmlStatement {
- private String dataverseName;
- private String datasetName;
- private String feedName;
+ private final String dataverseName;
+ private final String datasetName;
+ private final String feedName;
private Query query;
private int varCounter;
diff --git
a/asterix-app/src/main/java/org/apache/asterix/aql/translator/QueryTranslator.java
b/asterix-app/src/main/java/org/apache/asterix/aql/translator/QueryTranslator.java
index ea50221..0c3c88f 100644
---
a/asterix-app/src/main/java/org/apache/asterix/aql/translator/QueryTranslator.java
+++
b/asterix-app/src/main/java/org/apache/asterix/aql/translator/QueryTranslator.java
@@ -39,6 +39,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import com.google.common.collect.Lists;
import org.apache.asterix.api.common.APIFramework;
import org.apache.asterix.api.common.SessionConfig;
import org.apache.asterix.api.common.SessionConfig.OutputFormat;
@@ -984,7 +985,8 @@
ARecordType enforcedType = null;
if (stmtCreateIndex.isEnforced()) {
- enforcedType =
IntroduceSecondaryIndexInsertDeleteRule.createEnforcedType(aRecordType, index);
+ enforcedType =
IntroduceSecondaryIndexInsertDeleteRule.createEnforcedType(aRecordType,
+ Lists.newArrayList(index));
}
//#. prepare to create the index artifact in NC.
@@ -2443,36 +2445,34 @@
"Cannot compact the extrenal dataset " + datasetName +
" because it has no indexes");
}
- if (ds.getDatasetType() == DatasetType.INTERNAL) {
- for (int j = 0; j < indexes.size(); j++) {
- if (indexes.get(j).isSecondaryIndex()) {
- Dataverse dataverse = MetadataManager.INSTANCE
-
.getDataverse(metadataProvider.getMetadataTxnContext(), dataverseName);
- jobsToExecute
-
.add(DatasetOperations.compactDatasetJobSpec(dataverse, datasetName,
metadataProvider));
- }
- }
- } else {
- for (int j = 0; j < indexes.size(); j++) {
- if
(!ExternalIndexingOperations.isFileIndex(indexes.get(j))) {
- CompiledIndexCompactStatement cics = new
CompiledIndexCompactStatement(dataverseName,
- datasetName, indexes.get(j).getIndexName(),
indexes.get(j).getKeyFieldNames(),
- indexes.get(j).getKeyFieldTypes(),
indexes.get(j).isEnforcingKeyFileds(),
- indexes.get(j).getGramLength(),
indexes.get(j).getIndexType());
- ARecordType aRecordType = (ARecordType)
dt.getDatatype();
- ARecordType enforcedType = null;
- if (cics.isEnforced()) {
- enforcedType =
IntroduceSecondaryIndexInsertDeleteRule.createEnforcedType(aRecordType,
- indexes.get(j));
- }
-
jobsToExecute.add(IndexOperations.buildSecondaryIndexCompactJobSpec(cics,
aRecordType,
- enforcedType, metadataProvider, ds));
+ Dataverse dataverse = MetadataManager.INSTANCE
+ .getDataverse(metadataProvider.getMetadataTxnContext(),
dataverseName);
+ jobsToExecute
+ .add(DatasetOperations.compactDatasetJobSpec(dataverse,
datasetName, metadataProvider));
+ ARecordType aRecordType = (ARecordType) dt.getDatatype();
+ ARecordType enforcedType =
IntroduceSecondaryIndexInsertDeleteRule.createEnforcedType(aRecordType,
+ indexes);
+ for (int j = 0; j < indexes.size(); j++) {
+ boolean isInternalSecondary = ds.getDatasetType() ==
DatasetType.INTERNAL && indexes.get(j).isSecondaryIndex();
+ boolean isExternal = ds.getDatasetType() ==
DatasetType.EXTERNAL;
+ if (isInternalSecondary || (isExternal &&
!ExternalIndexingOperations.isFileIndex(indexes.get(j)))) {
+ CompiledIndexCompactStatement cics = new
CompiledIndexCompactStatement(dataverseName,
+ datasetName, indexes.get(j).getIndexName(),
indexes.get(j).getKeyFieldNames(),
+ indexes.get(j).getKeyFieldTypes(),
indexes.get(j).isEnforcingKeyFileds(),
+ indexes.get(j).getGramLength(),
indexes.get(j).getIndexType());
+
jobsToExecute.add(IndexOperations.buildSecondaryIndexCompactJobSpec(cics,
aRecordType,
+ enforcedType, metadataProvider, ds));
+
+ if (isExternal) {
+
jobsToExecute.add(ExternalIndexingOperations.compactFilesIndexJobSpec(ds,
metadataProvider));
}
}
-
jobsToExecute.add(ExternalIndexingOperations.compactFilesIndexJobSpec(ds,
metadataProvider));
+
}
+
jobsToExecute.add(ExternalIndexingOperations.compactFilesIndexJobSpec(ds,
metadataProvider));
+
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
bActiveTxn = false;
diff --git
a/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-2.plan
b/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-2.plan
index 25b3396..4b9e8a2 100644
---
a/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-2.plan
+++
b/asterix-app/src/test/resources/optimizerts/results/disjunction-to-join-delete-2.plan
@@ -9,7 +9,7 @@
-- INSERT_DELETE |PARTITIONED|
-- ONE_TO_ONE_EXCHANGE |PARTITIONED|
-- MATERIALIZE |PARTITIONED|
- -- ONE_TO_ONE_EXCHANGE |PARTITIONED|
+ -- HASH_PARTITION_EXCHANGE [$$8] |PARTITIONED|
-- ASSIGN |PARTITIONED|
-- STREAM_PROJECT |PARTITIONED|
-- STREAM_SELECT |PARTITIONED|
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-collision/index-type-collision.1.ddl.aql
similarity index 87%
rename from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
rename to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-collision/index-type-collision.1.ddl.aql
index 853386d..84d35b7 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-collision/index-type-collision.1.ddl.aql
@@ -21,9 +21,9 @@
use dataverse test;
create type testType as open {
- "id": int32,
- "value": string
+ "id": int32
}
create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+create index testIdx1 on testDS(value: int32) enforced;
+create index testIdx2 on testDS(value: string) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-promotion-collision/index-type-promotion-collision.1.ddl.aql
similarity index 87%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-promotion-collision/index-type-promotion-collision.1.ddl.aql
index 853386d..6c47032 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/index-type-promotion-collision/index-type-promotion-collision.1.ddl.aql
@@ -21,9 +21,9 @@
use dataverse test;
create type testType as open {
- "id": int32,
- "value": string
+ "id": int32
}
create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+create index testIdx1 on testDS(value: int64) enforced;
+create index testIdx2 on testDS(value: int32) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-type-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/record-type-collision/record-collision.1.ddl.aql
similarity index 100%
rename from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-type-collision/enforced-field-name-collision.1.ddl.aql
rename to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/record-type-collision/record-collision.1.ddl.aql
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.ddl.aql
new file mode 100644
index 0000000..10a3530
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.ddl.aql
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test that BTree open index is used in query plan
+ * : define the BTree open index on a composite key
(fname,lanme)
+ * : predicate => where $l.fname="Julio" and $l.lname="Isa"
+ * Expected Result : Success
+ * Issue : Issue 162
+ * Date : 27th March 2014
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type Emp as closed {
+id:int64,
+fname:string,
+lname:string,
+age:int64,
+dept:string
+}
+
+create type EmpOpen as open {
+id:int64,
+fname:string,
+age:int64,
+dept:string
+}
+
+create dataset employee(Emp) primary key id;
+
+create dataset employeeOpen(EmpOpen) primary key id;
+
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.update.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.update.aql
new file mode 100644
index 0000000..d28adff
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.update.aql
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+/*
+ * Description : Test that BTree enforced open index is used in query plan
+ * : define the BTree enforced open index on a composite key
(fname,lanme)
+ * : predicate => where $l.fname="Julio" and $l.lname="Isa"
+ * Expected Result : Success
+ * Issue : Issue 162
+ * Date : 27th March 2014
+ */
+
+use dataverse test;
+
+load dataset employee
+using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/names.adm"),("format"="delimited-text"),("delimiter"="|"));
+
+insert into dataset employeeOpen (
+ for $x in dataset employee return $x
+);
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.3.ddl.aql
similarity index 60%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.3.ddl.aql
index 853386d..11b0baa 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.3.ddl.aql
@@ -16,14 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
+/*
+ * Description : Test that BTree enforced open index is used in query plan
+ * : define the BTree enforced open index on a composite key
(fname,lanme)
+ * : predicate => where $l.fname="Julio" and $l.lname="Isa"
+ * Expected Result : Success
+ * Issue : Issue 162
+ * Date : 27th March 2014
+ */
+
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
-}
+// create secondary index
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+create index idx_employee_f_l_name on employeeOpen(fname,lname:string)
enforced;
+create index idx_employee_l_f_name on employeeOpen(lname:string, fname)
enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.4.query.aql
similarity index 60%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.4.query.aql
index 853386d..b1f2adf 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.4.query.aql
@@ -16,14 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
+/*
+ * Description : Test that BTree enforced open index is used in query plan
+ * : define the BTree enforced open index on a composite key
(fname,lanme)
+ * : predicate => where $l.fname="Julio" and $l.lname="Isa"
+ * Expected Result : Success
+ * Issue : Issue 162
+ * Date : 27th March 2014
+ */
+
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
+for $l in dataset('employeeOpen')
+where $l.fname="Julio" and $l.lname="Isa"
+return {
+ "id": $l.id,
+ "fname": $l.fname,
+ "lname": $l.lname,
+ "age": $l.age,
+ "dept": $l.dept
}
-
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.5.ddl.aql
similarity index 65%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.5.ddl.aql
index 853386d..4eaf8e8 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.5.ddl.aql
@@ -16,14 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
+/*
+ * Description : Test that BTree enforced open index is used in query plan
+ * : define the BTree enforced open index on a composite key
(fname,lanme)
+ * : predicate => where $l.fname="Julio" and $l.lname="Isa"
+ * Expected Result : Success
+ * Issue : Issue 162
+ * Date : 27th March 2014
+ */
+
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
-}
+// create secondary index
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+drop index employeeOpen.idx_employee_f_l_name;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.6.query.aql
similarity index 60%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.6.query.aql
index 853386d..b1f2adf 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.6.query.aql
@@ -16,14 +16,23 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
+/*
+ * Description : Test that BTree enforced open index is used in query plan
+ * : define the BTree enforced open index on a composite key
(fname,lanme)
+ * : predicate => where $l.fname="Julio" and $l.lname="Isa"
+ * Expected Result : Success
+ * Issue : Issue 162
+ * Date : 27th March 2014
+ */
+
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
+for $l in dataset('employeeOpen')
+where $l.fname="Julio" and $l.lname="Isa"
+return {
+ "id": $l.id,
+ "fname": $l.fname,
+ "lname": $l.lname,
+ "age": $l.age,
+ "dept": $l.dept
}
-
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.1.ddl.aql
similarity index 68%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.1.ddl.aql
index 853386d..0efffb2 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.1.ddl.aql
@@ -20,10 +20,24 @@
create dataverse test;
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
+create type DBLPType as closed {
+ id: int64,
+ dblpid: string,
+ title: string,
+ authors: string,
+ misc: string
}
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+create type DBLPOpenType as open {
+ id: int64,
+ dblpid: string,
+ authors: string,
+ misc: string
+}
+
+create nodegroup group1 if not exists on nc1, nc2;
+
+create dataset DBLP(DBLPType)
+ primary key id on group1;
+create dataset DBLPOpen(DBLPOpenType)
+ primary key id on group1;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.2.update.aql
similarity index 62%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.2.update.aql
index 853386d..3ee5d4e 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.2.update.aql
@@ -16,14 +16,25 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
-}
+load dataset DBLP
+using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter"
+(("path"="nc1://data/dblp-small/dblp-small-id.txt"),("format"="delimited-text"),("delimiter"=":"))
pre-sorted;
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+insert into dataset test.DBLPOpen (
+ for $x in dataset test.DBLP
+ where $x.id <= 50
+ return $x
+);
+
+insert into dataset test.DBLPOpen (
+ for $c in dataset test.DBLP
+ where $c.id > 50
+ return {
+ "id": $c.id,
+ "dblpid": $c.dblpid,
+ "authors": $c.authors,
+ "misc": $c.misc
+ }
+);
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.3.ddl.aql
similarity index 78%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.3.ddl.aql
index 853386d..98338b2 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.3.ddl.aql
@@ -16,14 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
+
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
-}
-
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
+create index ngram_index on DBLPOpen(title:string) type ngram(3) enforced;
+create index keyword_index on DBLPOpen(title:string) type keyword enforced;
+create index btree_index on DBLPOpen(title:string) enforced;
\ No newline at end of file
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.4.query.aql
similarity index 78%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.4.query.aql
index 853386d..775e97d 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.4.query.aql
@@ -16,14 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
+for $o in dataset('DBLPOpen')
+where contains($o.title, "Multimedia")
+order by $o.id
+return {
+ "id": $o.id,
+ "dblpid": $o.dblpid,
+ "title": $o.title,
+ "authors": $o.authors,
+ "misc": $o.misc
}
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.5.query.aql
similarity index 74%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.5.query.aql
index 853386d..b7423e2 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.5.query.aql
@@ -16,14 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
+
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
+for $o in dataset('DBLPOpen')
+let $jacc := similarity-jaccard-check(word-tokens($o.title),
word-tokens("Transactions for Cooperative Environments"), 0.5f)
+where $jacc[0]
+return {
+ "id": $o.id,
+ "dblpid": $o.dblpid,
+ "title": $o.title,
+ "authors": $o.authors,
+ "misc": $o.misc
}
-
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.6.query.aql
similarity index 77%
copy from
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
copy to
asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.6.query.aql
index 853386d..0e1ef29 100644
---
a/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/error-checking/enforced-field-name-collision/enforced-field-name-collision.1.ddl.aql
+++
b/asterix-app/src/test/resources/runtimets/queries/open-index-enforced/index-selection/multi-index/multi-index.6.query.aql
@@ -16,14 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-drop dataverse test if exists;
-create dataverse test;
use dataverse test;
-create type testType as open {
- "id": int32,
- "value": string
+for $o in dataset('DBLPOpen')
+where $o.title = "Multimedia Information Systems Issues and Approaches."
+order by $o.title
+return {
+ "id": $o.id,
+ "dblpid": $o.dblpid,
+ "title": $o.title,
+ "authors": $o.authors,
+ "misc": $o.misc
}
-
-create dataset testDS(testType) primary key id;
-create index testIdx on testDS(value: string) enforced;
diff --git
a/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.adm
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.adm
new file mode 100644
index 0000000..1e19d0d
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.1.adm
@@ -0,0 +1,2 @@
+[ { "id": 881, "fname": "Julio", "age": 38, "dept": "Sales", "lname": "Isa" }
+ ]
diff --git
a/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.adm
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.adm
new file mode 100644
index 0000000..1e19d0d
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index-composite-key/multi-index-composite-key.2.adm
@@ -0,0 +1,2 @@
+[ { "id": 881, "fname": "Julio", "age": 38, "dept": "Sales", "lname": "Isa" }
+ ]
diff --git
a/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.1.adm
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.1.adm
new file mode 100644
index 0000000..61ee356
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.1.adm
@@ -0,0 +1,2 @@
+[ { "id": 4, "dblpid": "books/acm/kim95/ChristodoulakisK95", "authors":
"Stavros Christodoulakis Leonidas Koveos", "misc": "2002-01-03 318-337 1995
Modern Database Systems db/books/collections/kim95.html#ChristodoulakisK95",
"title": "Multimedia Information Systems Issues and Approaches." }
+ ]
\ No newline at end of file
diff --git
a/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.2.adm
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.2.adm
new file mode 100644
index 0000000..d7647ff
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.2.adm
@@ -0,0 +1,2 @@
+[ { "id": 9, "dblpid": "books/acm/kim95/Kaiser95", "authors": "Gail E.
Kaiser", "misc": "2002-01-03 409-433 1995 Modern Database Systems
db/books/collections/kim95.html#Kaiser95", "title": "Cooperative Transactions
for Multiuser Environments." }
+ ]
\ No newline at end of file
diff --git
a/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.3.adm
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.3.adm
new file mode 100644
index 0000000..61ee356
--- /dev/null
+++
b/asterix-app/src/test/resources/runtimets/results/open-index-enforced/index-selection/multi-index/multi-index.3.adm
@@ -0,0 +1,2 @@
+[ { "id": 4, "dblpid": "books/acm/kim95/ChristodoulakisK95", "authors":
"Stavros Christodoulakis Leonidas Koveos", "misc": "2002-01-03 318-337 1995
Modern Database Systems db/books/collections/kim95.html#ChristodoulakisK95",
"title": "Multimedia Information Systems Issues and Approaches." }
+ ]
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml
b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 758c393..0535f77 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -2986,15 +2986,22 @@
</test-group>
<test-group name="open-index-enforced">
<test-group FilePath="open-index-enforced/error-checking">
- <test-case FilePath="open-index-enforced/error-checking"><!-- This
test case doesn't throw an exception? commenting it out -->
- <compilation-unit name="enforced-field-name-collision">
- <output-dir
compare="Text">enforced-field-name-collision</output-dir>
- <!--
<expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException</expected-error>
-->
+ <test-case FilePath="open-index-enforced/error-checking">
+ <compilation-unit name="index-on-closed-type">
+ <output-dir
compare="Text">index-on-closed-type</output-dir>
+
<expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException
+ </expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="open-index-enforced/error-checking">
- <compilation-unit name="enforced-field-type-collision">
- <output-dir
compare="Text">enforced-field-type-collision</output-dir>
+ <compilation-unit name="index-type-collision">
+ <output-dir
compare="Text">index-type-collision</output-dir>
+ <expected-error>SyntaxError: A field "[value]" is already
defined with the type "STRING"</expected-error>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="open-index-enforced/error-checking">
+ <compilation-unit name="index-type-promotion-collision">
+ <output-dir
compare="Text">index-type-promotion-collision</output-dir>
<expected-error>SyntaxError: A field "[value]" is already
defined with the type "STRING"</expected-error>
</compilation-unit>
</test-case>
@@ -3005,8 +3012,8 @@
</compilation-unit>
</test-case>
<test-case FilePath="open-index-enforced/error-checking">
- <compilation-unit name="index-on-closed-type">
- <output-dir
compare="Text">index-on-closed-type</output-dir>
+ <compilation-unit name="record-type-collision">
+ <output-dir
compare="Text">record-type-collision</output-dir>
<expected-error>org.apache.hyracks.algebricks.common.exceptions.AlgebricksException:
Typed index on "[value]" field could be created only for open
datatype</expected-error>
</compilation-unit>
</test-case>
@@ -3142,6 +3149,16 @@
</compilation-unit>
</test-case>
<test-case FilePath="open-index-enforced/index-selection">
+ <compilation-unit name="multi-index">
+ <output-dir compare="Text">multi-index</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="open-index-enforced/index-selection">
+ <compilation-unit name="multi-index-composite-key">
+ <output-dir
compare="Text">multi-index-composite-key</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="open-index-enforced/index-selection">
<compilation-unit name="orders-index-custkey">
<output-dir
compare="Text">orders-index-custkey</output-dir>
</compilation-unit>
--
To view, visit https://asterix-gerrit.ics.uci.edu/712
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8fcf41c009f9faf51bc8bccc0c3c7217b7769121
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Ildar Absalyamov <[email protected]>