use of org.apache.asterix.metadata.declared.MetadataProvider in project asterixdb by apache.
the class TestNodeController method createPrimaryIndex.
public void createPrimaryIndex(Dataset dataset, IAType[] primaryKeyTypes, ARecordType recordType, ARecordType metaType, ILSMMergePolicyFactory mergePolicyFactory, Map<String, String> mergePolicyProperties, int[] filterFields, IStorageComponentProvider storageComponentProvider, int[] primaryKeyIndexes, List<Integer> primaryKeyIndicators) throws AlgebricksException, HyracksDataException {
PrimaryIndexInfo primaryIndexInfo = new PrimaryIndexInfo(dataset, primaryKeyTypes, recordType, metaType, mergePolicyFactory, mergePolicyProperties, filterFields, primaryKeyIndexes, primaryKeyIndicators, storageComponentProvider);
Dataverse dataverse = new Dataverse(dataset.getDataverseName(), NonTaggedDataFormat.class.getName(), MetadataUtil.PENDING_NO_OP);
MetadataProvider mdProvider = new MetadataProvider((ICcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext(), dataverse, storageComponentProvider);
try {
IResourceFactory resourceFactory = dataset.getResourceFactory(mdProvider, primaryIndexInfo.index, recordType, metaType, mergePolicyFactory, mergePolicyProperties);
IndexBuilderFactory indexBuilderFactory = new IndexBuilderFactory(storageComponentProvider.getStorageManager(), primaryIndexInfo.fileSplitProvider, resourceFactory, !dataset.isTemp());
IHyracksTaskContext ctx = createTestContext(false);
IIndexBuilder indexBuilder = indexBuilderFactory.create(ctx, 0);
indexBuilder.build();
} finally {
mdProvider.getLocks().unlock();
}
}
use of org.apache.asterix.metadata.declared.MetadataProvider in project asterixdb by apache.
the class TestNodeController method getPrimaryResourceFactory.
public IResourceFactory getPrimaryResourceFactory(IHyracksTaskContext ctx, PrimaryIndexInfo primaryIndexInfo, IStorageComponentProvider storageComponentProvider, Dataset dataset) throws AlgebricksException {
Dataverse dataverse = new Dataverse(dataset.getDataverseName(), NonTaggedDataFormat.class.getName(), MetadataUtil.PENDING_NO_OP);
Index index = primaryIndexInfo.getIndex();
CcApplicationContext appCtx = (CcApplicationContext) ExecutionTestUtil.integrationUtil.cc.getApplicationContext();
MetadataProvider mdProvider = new MetadataProvider(appCtx, dataverse, storageComponentProvider);
try {
return dataset.getResourceFactory(mdProvider, index, primaryIndexInfo.recordType, primaryIndexInfo.metaType, primaryIndexInfo.mergePolicyFactory, primaryIndexInfo.mergePolicyProperties);
} finally {
mdProvider.getLocks().unlock();
}
}
use of org.apache.asterix.metadata.declared.MetadataProvider in project asterixdb by apache.
the class ParserTestExecutor method testSQLPPParser.
// Tests the SQL++ parser.
public void testSQLPPParser(File queryFile, File actualResultFile, File expectedFile) throws Exception {
actualResultFile.getParentFile().mkdirs();
PrintWriter writer = new PrintWriter(new FileOutputStream(actualResultFile));
IParser parser = sqlppParserFactory.createParser(readTestFile(queryFile));
GlobalConfig.ASTERIX_LOGGER.info(queryFile.toString());
try {
List<Statement> statements = parser.parse();
List<FunctionDecl> functions = getDeclaredFunctions(statements);
String dvName = getDefaultDataverse(statements);
MetadataProvider metadataProvider = mock(MetadataProvider.class);
@SuppressWarnings("unchecked") Map<String, String> config = mock(Map.class);
when(metadataProvider.getDefaultDataverseName()).thenReturn(dvName);
when(metadataProvider.getConfig()).thenReturn(config);
when(config.get(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS)).thenReturn("true");
when(metadataProvider.findDataset(anyString(), anyString())).thenReturn(mock(Dataset.class));
for (Statement st : statements) {
if (st.getKind() == Statement.Kind.QUERY) {
Query query = (Query) st;
IQueryRewriter rewriter = sqlppRewriterFactory.createQueryRewriter();
rewrite(rewriter, functions, query, metadataProvider, new LangRewritingContext(query.getVarCounter()));
// Tests deep copy and deep equality.
Query copiedQuery = (Query) SqlppRewriteUtil.deepCopy(query);
Assert.assertEquals(query.hashCode(), copiedQuery.hashCode());
Assert.assertEquals(query, copiedQuery);
}
SqlppAstPrintUtil.print(st, writer);
}
writer.close();
// Compares the actual result and the expected result.
runScriptAndCompareWithResult(queryFile, new PrintWriter(System.err), expectedFile, actualResultFile, ComparisonEnum.TEXT);
} catch (Exception e) {
GlobalConfig.ASTERIX_LOGGER.warning("Failed while testing file " + queryFile);
throw e;
} finally {
writer.close();
}
}
use of org.apache.asterix.metadata.declared.MetadataProvider in project asterixdb by apache.
the class AqlQueryRewriter method inlineDeclaredUdfs.
private void inlineDeclaredUdfs() throws CompilationException {
if (topStatement == null) {
return;
}
List<FunctionSignature> funIds = new ArrayList<FunctionSignature>();
for (FunctionDecl fdecl : declaredFunctions) {
funIds.add(fdecl.getSignature());
}
List<FunctionDecl> storedFunctionDecls = new ArrayList<>();
for (Expression topLevelExpr : topStatement.getDirectlyEnclosedExpressions()) {
storedFunctionDecls.addAll(FunctionUtil.retrieveUsedStoredFunctions(metadataProvider, topLevelExpr, funIds, null, expr -> getFunctionCalls(expr), func -> functionParser.getFunctionDecl(func), signature -> CommonFunctionMapUtil.normalizeBuiltinFunctionSignature(signature)));
declaredFunctions.addAll(storedFunctionDecls);
}
if (!declaredFunctions.isEmpty()) {
AQLInlineUdfsVisitor visitor = new AQLInlineUdfsVisitor(context, new AQLRewriterFactory(), declaredFunctions, metadataProvider);
while (topStatement.accept(visitor, declaredFunctions)) {
// loop until no more changes
}
}
declaredFunctions.removeAll(storedFunctionDecls);
}
use of org.apache.asterix.metadata.declared.MetadataProvider in project asterixdb by apache.
the class MetadataBuiltinFunctions method addMetadataBuiltinFunctions.
public static void addMetadataBuiltinFunctions() {
BuiltinFunctions.addFunction(BuiltinFunctions.DATASET, new IResultTypeComputer() {
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp) throws AlgebricksException {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
if (f.getArguments().size() != 1) {
throw new AlgebricksException("dataset arity is 1, not " + f.getArguments().size());
}
ILogicalExpression a1 = f.getArguments().get(0).getValue();
IAType t1 = (IAType) env.getType(a1);
if (t1.getTypeTag() == ATypeTag.ANY) {
return BuiltinType.ANY;
}
if (t1.getTypeTag() != ATypeTag.STRING) {
throw new AlgebricksException("Illegal type " + t1 + " for dataset() argument.");
}
String datasetArg = ConstantExpressionUtil.getStringConstant(a1);
if (datasetArg == null) {
return BuiltinType.ANY;
}
MetadataProvider metadata = (MetadataProvider) mp;
Pair<String, String> datasetInfo = getDatasetInfo(metadata, datasetArg);
String dataverseName = datasetInfo.first;
String datasetName = datasetInfo.second;
if (dataverseName == null) {
throw new AlgebricksException("Unspecified dataverse!");
}
Dataset dataset = metadata.findDataset(dataverseName, datasetName);
if (dataset == null) {
throw new AlgebricksException("Could not find dataset " + datasetName + " in dataverse " + dataverseName);
}
String tn = dataset.getItemTypeName();
IAType t2 = metadata.findType(dataset.getItemTypeDataverseName(), tn);
if (t2 == null) {
throw new AlgebricksException("No type for dataset " + datasetName);
}
return t2;
}
}, true);
BuiltinFunctions.addPrivateFunction(BuiltinFunctions.FEED_COLLECT, new IResultTypeComputer() {
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp) throws AlgebricksException {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
if (f.getArguments().size() != BuiltinFunctions.FEED_COLLECT.getArity()) {
throw new AlgebricksException("Incorrect number of arguments -> arity is " + BuiltinFunctions.FEED_COLLECT.getArity() + ", not " + f.getArguments().size());
}
ILogicalExpression a1 = f.getArguments().get(5).getValue();
IAType t1 = (IAType) env.getType(a1);
if (t1.getTypeTag() == ATypeTag.ANY) {
return BuiltinType.ANY;
}
if (t1.getTypeTag() != ATypeTag.STRING) {
throw new AlgebricksException("Illegal type " + t1 + " for feed-ingest argument.");
}
String typeArg = ConstantExpressionUtil.getStringConstant(a1);
if (typeArg == null) {
return BuiltinType.ANY;
}
MetadataProvider metadata = (MetadataProvider) mp;
Pair<String, String> argInfo = getDatasetInfo(metadata, typeArg);
String dataverseName = argInfo.first;
String typeName = argInfo.second;
if (dataverseName == null) {
throw new AlgebricksException("Unspecified dataverse!");
}
IAType t2 = metadata.findType(dataverseName, typeName);
if (t2 == null) {
throw new AlgebricksException("Unknown type " + typeName);
}
return t2;
}
}, true);
BuiltinFunctions.addFunction(BuiltinFunctions.FEED_INTERCEPT, new IResultTypeComputer() {
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp) throws AlgebricksException {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
if (f.getArguments().size() != 1) {
throw new AlgebricksException("dataset arity is 1, not " + f.getArguments().size());
}
ILogicalExpression a1 = f.getArguments().get(0).getValue();
IAType t1 = (IAType) env.getType(a1);
if (t1.getTypeTag() == ATypeTag.ANY) {
return BuiltinType.ANY;
}
if (t1.getTypeTag() != ATypeTag.STRING) {
throw new AlgebricksException("Illegal type " + t1 + " for dataset() argument.");
}
String datasetArg = ConstantExpressionUtil.getStringConstant(a1);
if (datasetArg == null) {
return BuiltinType.ANY;
}
MetadataProvider metadata = (MetadataProvider) mp;
Pair<String, String> datasetInfo = getDatasetInfo(metadata, datasetArg);
String dataverseName = datasetInfo.first;
String datasetName = datasetInfo.second;
if (dataverseName == null) {
throw new AlgebricksException("Unspecified dataverse!");
}
Dataset dataset = metadata.findDataset(dataverseName, datasetName);
if (dataset == null) {
throw new AlgebricksException("Could not find dataset " + datasetName + " in dataverse " + dataverseName);
}
String tn = dataset.getItemTypeName();
IAType t2 = metadata.findType(dataset.getItemTypeDataverseName(), tn);
if (t2 == null) {
throw new AlgebricksException("No type for dataset " + datasetName);
}
return t2;
}
}, true);
}
Aggregations