use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class DocTableInfoBuilder method docIndexMetaData.
private DocIndexMetaData docIndexMetaData() {
DocIndexMetaData docIndexMetaData;
String templateName = PartitionName.templateName(ident.schema(), ident.name());
boolean createdFromTemplate = false;
if (metaData.getTemplates().containsKey(templateName)) {
docIndexMetaData = buildDocIndexMetaDataFromTemplate(ident.indexName(), templateName);
createdFromTemplate = true;
concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.lenientExpandOpen(), ident.indexName());
} else {
try {
concreteIndices = indexNameExpressionResolver.concreteIndices(state, IndicesOptions.strictExpandOpen(), ident.indexName());
if (concreteIndices.length == 0) {
// no matching index found
throw new TableUnknownException(ident);
}
docIndexMetaData = buildDocIndexMetaData(concreteIndices[0]);
} catch (IndexNotFoundException ex) {
throw new TableUnknownException(ident.fqn(), ex);
}
}
if ((!createdFromTemplate && concreteIndices.length == 1) || !checkAliasSchema) {
return docIndexMetaData;
}
for (String concreteIndice : concreteIndices) {
if (IndexMetaData.State.CLOSE.equals(metaData.indices().get(concreteIndice).getState())) {
throw new UnhandledServerException(String.format(Locale.ENGLISH, "Unable to access the partition %s, it is closed", concreteIndice));
}
try {
docIndexMetaData = docIndexMetaData.merge(buildDocIndexMetaData(concreteIndice), transportPutIndexTemplateAction, createdFromTemplate);
} catch (IOException e) {
throw new UnhandledServerException("Unable to merge/build new DocIndexMetaData", e);
}
}
return docIndexMetaData;
}
use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class DocTableInfoBuilder method buildDocIndexMetaDataFromTemplate.
private DocIndexMetaData buildDocIndexMetaDataFromTemplate(String index, String templateName) {
IndexTemplateMetaData indexTemplateMetaData = metaData.getTemplates().get(templateName);
DocIndexMetaData docIndexMetaData;
try {
IndexMetaData.Builder builder = new IndexMetaData.Builder(index);
builder.putMapping(Constants.DEFAULT_MAPPING_TYPE, indexTemplateMetaData.getMappings().get(Constants.DEFAULT_MAPPING_TYPE).toString());
Settings.Builder settingsBuilder = Settings.builder().put(indexTemplateMetaData.settings()).put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
Settings settings = settingsBuilder.build();
builder.settings(settings);
builder.numberOfShards(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
builder.numberOfReplicas(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
docIndexMetaData = new DocIndexMetaData(functions, builder.build(), ident);
} catch (IOException e) {
throw new UnhandledServerException("Unable to build DocIndexMetaData from template", e);
}
return docIndexMetaData.build();
}
use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class LuceneReferenceResolver method getImplementation.
@Override
public LuceneCollectorExpression<?> getImplementation(Reference refInfo) {
assert refInfo.granularity() == RowGranularity.DOC : "lucene collector expressions are required to be on DOC granularity";
ColumnIdent columnIdent = refInfo.ident().columnIdent();
String name = columnIdent.name();
if (RawCollectorExpression.COLUMN_NAME.equals(name)) {
if (columnIdent.isColumn()) {
return new RawCollectorExpression();
} else {
// TODO: implement an Object source expression which may support subscripts
throw new UnsupportedFeatureException(String.format(Locale.ENGLISH, "_source expression does not support subscripts %s", columnIdent.fqn()));
}
} else if (UidCollectorExpression.COLUMN_NAME.equals(name)) {
return new UidCollectorExpression();
} else if (IdCollectorExpression.COLUMN_NAME.equals(name)) {
return new IdCollectorExpression();
} else if (DocCollectorExpression.COLUMN_NAME.equals(name)) {
return DocCollectorExpression.create(refInfo);
} else if (FetchIdCollectorExpression.COLUMN_NAME.equals(name)) {
return new FetchIdCollectorExpression();
} else if (ScoreCollectorExpression.COLUMN_NAME.equals(name)) {
return new ScoreCollectorExpression();
}
String colName = columnIdent.fqn();
MappedFieldType fieldType = fieldTypeLookup.get(colName);
if (fieldType == null) {
return new NullValueCollectorExpression(colName);
}
switch(refInfo.valueType().id()) {
case ByteType.ID:
return new ByteColumnReference(colName);
case ShortType.ID:
return new ShortColumnReference(colName);
case IpType.ID:
return new IpColumnReference(colName);
case StringType.ID:
return new BytesRefColumnReference(colName, fieldType);
case DoubleType.ID:
return new DoubleColumnReference(colName, fieldType);
case BooleanType.ID:
return new BooleanColumnReference(colName);
case ObjectType.ID:
return new ObjectColumnReference(colName);
case FloatType.ID:
return new FloatColumnReference(colName, fieldType);
case LongType.ID:
case TimestampType.ID:
return new LongColumnReference(colName);
case IntegerType.ID:
return new IntegerColumnReference(colName);
case GeoPointType.ID:
return new GeoPointColumnReference(colName, fieldType);
case GeoShapeType.ID:
return new GeoShapeColumnReference(colName);
case ArrayType.ID:
case SetType.ID:
return DocCollectorExpression.create(DocReferenceConverter.toSourceLookup(refInfo));
default:
throw new UnhandledServerException(String.format(Locale.ENGLISH, "unsupported type '%s'", refInfo.valueType().getName()));
}
}
use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class AccessControlMaySeeTest method testUnscopedException.
@Test
public void testUnscopedException() throws Exception {
accessControl.ensureMaySee(new UnhandledServerException("unhandled"));
assertThat(validationCallArguments.size(), is(0));
}
use of io.crate.exceptions.UnhandledServerException in project crate by crate.
the class DocTableInfoBuilder method buildDocIndexMetadataFromTemplate.
private DocIndexMetadata buildDocIndexMetadataFromTemplate(String index, String templateName) {
IndexTemplateMetadata indexTemplateMetadata = metadata.getTemplates().get(templateName);
DocIndexMetadata docIndexMetadata;
try {
IndexMetadata.Builder builder = new IndexMetadata.Builder(index);
builder.putMapping(Constants.DEFAULT_MAPPING_TYPE, indexTemplateMetadata.getMappings().get(Constants.DEFAULT_MAPPING_TYPE).toString());
Settings.Builder settingsBuilder = Settings.builder().put(indexTemplateMetadata.settings()).put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT);
Settings settings = settingsBuilder.build();
builder.settings(settings);
builder.numberOfShards(settings.getAsInt(SETTING_NUMBER_OF_SHARDS, 5));
builder.numberOfReplicas(settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, 1));
docIndexMetadata = new DocIndexMetadata(nodeCtx, builder.build(), ident);
} catch (IOException e) {
throw new UnhandledServerException("Unable to build DocIndexMetadata from template", e);
}
return docIndexMetadata.build();
}
Aggregations