public XMLQueryCompiler(XQueryCompilationListener listener, String[] nodeList, int frameSize,
int availableProcessors, int joinHashSize) {
this.listener = listener == null ? NoopXQueryCompilationListener.INSTANCE : listener;
this.frameSize = frameSize;
this.nodeList = nodeList;
HeuristicCompilerFactoryBuilder builder = new HeuristicCompilerFactoryBuilder(
new IOptimizationContextFactory() {
@Override
public IOptimizationContext createOptimizationContext(int varCounter,
IExpressionEvalSizeComputer expressionEvalSizeComputer,
IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
IExpressionTypeComputer expressionTypeComputer, INullableTypeComputer nullableTypeComputer,
PhysicalOptimizationConfig physicalOptimizationConfig) {
return new VXQueryOptimizationContext(varCounter, expressionEvalSizeComputer,
mergeAggregationExpressionFactory, expressionTypeComputer, nullableTypeComputer,
physicalOptimizationConfig, pprinter);
}
});
builder.getPhysicalOptimizationConfig().setFrameSize(this.frameSize);
if (joinHashSize > 0) {
builder.getPhysicalOptimizationConfig().setInMemHashJoinTableSize(joinHashSize);
}
builder.setLogicalRewrites(buildDefaultLogicalRewrites());
builder.setPhysicalRewrites(buildDefaultPhysicalRewrites());
builder.setSerializerDeserializerProvider(new ISerializerDeserializerProvider() {
@SuppressWarnings("unchecked")
@Override
public ISerializerDeserializer getSerializerDeserializer(Object type) throws AlgebricksException {
return null;
}
});
builder.setHashFunctionFactoryProvider(VXQueryBinaryHashFunctionFactoryProvider.INSTANCE);
builder.setHashFunctionFamilyProvider(VXQueryBinaryHashFunctionFamilyProvider.INSTANCE);
builder.setTypeTraitProvider(new ITypeTraitProvider() {
@Override
public ITypeTraits getTypeTrait(Object type) {
return VoidPointable.TYPE_TRAITS;
}
});
builder.setPrinterProvider(VXQueryPrinterFactoryProvider.INSTANCE);
builder.setExpressionRuntimeProvider(new VXQueryExpressionRuntimeProvider());
builder.setComparatorFactoryProvider(new VXQueryComparatorFactoryProvider());
builder.setBinaryBooleanInspectorFactory(new VXQueryBinaryBooleanInspectorFactory());
builder.setBinaryIntegerInspectorFactory(new VXQueryBinaryIntegerInspectorFactory());
builder.setExpressionTypeComputer(new IExpressionTypeComputer() {
@Override
public Object getType(ILogicalExpression expr, IMetadataProvider<?, ?> metadataProvider,
IVariableTypeEnvironment env) throws AlgebricksException {
if (expr.getExpressionTag() == LogicalExpressionTag.CONSTANT) {
ConstantExpression ce = (ConstantExpression) expr;
IAlgebricksConstantValue acv = ce.getValue();
if (acv == ConstantExpression.TRUE.getValue() || acv == ConstantExpression.FALSE.getValue()) {
return SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE);
}
VXQueryConstantValue cv = (VXQueryConstantValue) acv;
return cv.getType();
}
return null;
}
});
builder.setNullableTypeComputer(new INullableTypeComputer() {
@Override
public Object makeNullableType(Object type) throws AlgebricksException {
throw new NotImplementedException("NullableTypeComputer is not implented");
}
});
builder.setNullWriterFactory(new VXQueryNullWriterFactory());
if (availableProcessors < 1) {
builder.setClusterLocations(VXQueryMetadataProvider.getClusterLocations(nodeList));
} else {
builder.setClusterLocations(VXQueryMetadataProvider.getClusterLocations(nodeList, availableProcessors));
}
cFactory = builder.create();
}