Skip to content
Permalink
Browse files
Coordinated change for function metadata cleanup
Change-Id: I4c5238a6e92b89410bbffc0c9338b36c61896a6b
  • Loading branch information
Dmitry Lychagin committed Feb 5, 2020
1 parent 80ab7db commit 29a2cc9fcac765fcf217924abaf04521c4c431f3
Showing 3 changed files with 19 additions and 9 deletions.
@@ -57,6 +57,7 @@
import org.apache.asterix.lang.common.struct.VarIdentifier;
import org.apache.asterix.lang.common.util.FunctionUtil;
import org.apache.asterix.lang.common.visitor.base.ILangVisitor;
import org.apache.asterix.lang.sqlpp.parser.SqlppParserFactory;
import org.apache.asterix.lang.sqlpp.rewrites.SqlppRewriterFactory;
import org.apache.asterix.lang.sqlpp.util.SqlppStatementUtil;
import org.apache.asterix.lang.sqlpp.visitor.SqlppDeleteRewriteVisitor;
@@ -191,7 +192,7 @@ private Pair<JobSpecification, PrecompiledType> createProcedureJob(IStatementExe
PrecompiledType.INSERT);
} else if (getProcedureBodyStatement().getKind() == Statement.Kind.QUERY) {
//TODO: Fix type dependency computation
SqlppRewriterFactory fact = new SqlppRewriterFactory();
SqlppRewriterFactory fact = new SqlppRewriterFactory(new SqlppParserFactory());
dependencies.get(1)
.addAll(FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(),
((Query) getProcedureBodyStatement()).getBody(), metadataProvider, new ArrayList<>())
@@ -207,7 +208,7 @@ private Pair<JobSpecification, PrecompiledType> createProcedureJob(IStatementExe
getProcedureBodyStatement().accept(SqlppDeleteRewriteVisitor.INSTANCE, metadataProvider);
DeleteStatement delete = (DeleteStatement) getProcedureBodyStatement();

SqlppRewriterFactory fact = new SqlppRewriterFactory();
SqlppRewriterFactory fact = new SqlppRewriterFactory(new SqlppParserFactory());
dependencies = FunctionUtil.getFunctionDependencies(fact.createQueryRewriter(), delete.getQuery().getBody(),
metadataProvider, new ArrayList<>());
Pair<JobSpecification, PrecompiledType> pair =
@@ -272,7 +273,7 @@ public void handle(IHyracksClientConnection hcc, IStatementExecutor statementExe
stats);

procedure = new Procedure(dataverse, signature.getName(), signature.getArity(), getParamList(),
procedureJobSpec.second.toString(), getProcedureBody(), Function.LANGUAGE_SQLPP, duration,
procedureJobSpec.second.toString(), getProcedureBody(), Function.FunctionLanguage.SQLPP, duration,
dependencies);

MetadataManager.INSTANCE.addEntity(mdTxnCtx, procedure);
@@ -26,6 +26,7 @@
import org.apache.asterix.common.metadata.DataverseName;
import org.apache.asterix.metadata.api.ExtensionMetadataDatasetId;
import org.apache.asterix.metadata.api.IExtensionMetadataEntity;
import org.apache.asterix.metadata.entities.Function;
import org.apache.hyracks.algebricks.common.utils.Triple;

public class Procedure implements IExtensionMetadataEntity {
@@ -37,7 +38,7 @@ public class Procedure implements IExtensionMetadataEntity {
private final List<String> params;
private final String body;
private final String type;
private final String language;
private final Function.FunctionLanguage language;
private final String duration;
/*
Dependencies are stored as an array of size two:
@@ -49,7 +50,7 @@ public class Procedure implements IExtensionMetadataEntity {
private final List<List<Triple<DataverseName, String, String>>> dependencies;

public Procedure(DataverseName dataverseName, String functionName, int arity, List<String> params, String type,
String functionBody, String language, String duration,
String functionBody, Function.FunctionLanguage language, String duration,
List<List<Triple<DataverseName, String, String>>> dependencies) {
this.procedureId = new EntityId(BADConstants.PROCEDURE_KEYWORD, dataverseName, functionName);
this.params = params;
@@ -83,7 +84,7 @@ public String getType() {
return type;
}

public String getLanguage() {
public Function.FunctionLanguage getLanguage() {
return language;
}

@@ -23,15 +23,19 @@
import java.util.List;

import org.apache.asterix.builders.OrderedListBuilder;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.common.exceptions.ErrorCode;
import org.apache.asterix.common.exceptions.MetadataException;
import org.apache.asterix.common.metadata.DataverseName;
import org.apache.asterix.metadata.entities.Function;
import org.apache.asterix.metadata.entitytupletranslators.AbstractTupleTranslator;
import org.apache.asterix.om.base.AOrderedList;
import org.apache.asterix.om.base.ARecord;
import org.apache.asterix.om.base.AString;
import org.apache.asterix.om.base.IACursor;
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.common.utils.Triple;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
@@ -65,7 +69,7 @@ protected ProcedureTupleTranslator(boolean getTuple) {
}

@Override
public Procedure createMetadataEntityFromARecord(ARecord procedureRecord) throws HyracksDataException {
public Procedure createMetadataEntityFromARecord(ARecord procedureRecord) throws AlgebricksException {
String dataverseCanonicalName = ((AString) procedureRecord
.getValueByPos(BADMetadataRecordTypes.PROCEDURE_ARECORD_DATAVERSENAME_FIELD_INDEX)).getStringValue();
DataverseName dataverseName = DataverseName.createFromCanonicalForm(dataverseCanonicalName);
@@ -88,9 +92,13 @@ public Procedure createMetadataEntityFromARecord(ARecord procedureRecord) throws
.getValueByPos(BADMetadataRecordTypes.PROCEDURE_ARECORD_PROCEDURE_DEFINITION_FIELD_INDEX))
.getStringValue();

String language = ((AString) procedureRecord
String languageValue = ((AString) procedureRecord
.getValueByPos(BADMetadataRecordTypes.PROCEDURE_ARECORD_PROCEDURE_LANGUAGE_FIELD_INDEX))
.getStringValue();
Function.FunctionLanguage language = Function.FunctionLanguage.findByName(languageValue);
if (language == null) {
throw new AsterixException(ErrorCode.METADATA_ERROR, languageValue);
}

String duration = ((AString) procedureRecord
.getValueByPos(BADMetadataRecordTypes.PROCEDURE_ARECORD_PROCEDURE_DURATION_FIELD_INDEX))
@@ -196,7 +204,7 @@ public ITupleReference getTupleFromMetadataEntity(Procedure procedure)

// write field 6
fieldValue.reset();
aString.setValue(procedure.getLanguage());
aString.setValue(procedure.getLanguage().getName());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(BADMetadataRecordTypes.PROCEDURE_ARECORD_PROCEDURE_LANGUAGE_FIELD_INDEX, fieldValue);

0 comments on commit 29a2cc9

Please sign in to comment.