use of io.crate.metadata.CoordinatorTxnCtx in project crate by crate.
the class CreateBlobTablePlan method buildSettings.
@VisibleForTesting
public static Settings buildSettings(CreateBlobTable<Symbol> createBlobTable, CoordinatorTxnCtx txnCtx, NodeContext nodeCtx, Row params, SubQueryResults subQueryResults, NumberOfShards numberOfShards) {
Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(txnCtx, nodeCtx, x, params, subQueryResults);
CreateBlobTable<Object> blobTable = createBlobTable.map(eval);
GenericProperties<Object> properties = blobTable.genericProperties();
// apply default in case it is not specified in the properties,
// if it is it will get overwritten afterwards.
TableParameter tableParameter = new TableParameter();
TablePropertiesAnalyzer.analyzeWithBoundValues(tableParameter, TableParameters.CREATE_BLOB_TABLE_PARAMETERS, properties, true);
Settings.Builder builder = Settings.builder();
builder.put(tableParameter.settings());
builder.put(SETTING_INDEX_BLOBS_ENABLED.getKey(), true);
int numShards;
ClusteredBy<Object> clusteredBy = blobTable.clusteredBy();
if (clusteredBy != null) {
numShards = numberOfShards.fromClusteredByClause(clusteredBy);
} else {
numShards = numberOfShards.defaultNumberOfShards();
}
builder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numShards);
return builder.build();
}
use of io.crate.metadata.CoordinatorTxnCtx in project crate by crate.
the class ReservoirSampler method getSamples.
public Samples getSamples(RelationName relationName, List<Reference> columns, int maxSamples) {
TableInfo table;
try {
table = schemas.getTableInfo(relationName);
} catch (RelationUnknown e) {
return Samples.EMPTY;
}
if (!(table instanceof DocTableInfo)) {
return Samples.EMPTY;
}
DocTableInfo docTable = (DocTableInfo) table;
Random random = Randomness.get();
Metadata metadata = clusterService.state().metadata();
CoordinatorTxnCtx coordinatorTxnCtx = CoordinatorTxnCtx.systemTransactionContext();
List<Streamer> streamers = Arrays.asList(Symbols.streamerArray(columns));
List<Engine.Searcher> searchersToRelease = new ArrayList<>();
CircuitBreaker breaker = circuitBreakerService.getBreaker(HierarchyCircuitBreakerService.QUERY);
RamAccounting ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, "Reservoir-sampling"), MAX_BLOCK_SIZE_IN_BYTES);
try {
return getSamples(columns, maxSamples, docTable, random, metadata, coordinatorTxnCtx, streamers, searchersToRelease, ramAccounting);
} finally {
ramAccounting.close();
for (Engine.Searcher searcher : searchersToRelease) {
searcher.close();
}
}
}
use of io.crate.metadata.CoordinatorTxnCtx in project crate by crate.
the class DocKeysTest method testClusteredIsFirstInId.
@Test
public void testClusteredIsFirstInId() throws Exception {
// if a the table is clustered and has a pk, the clustering value is put in front in the id computation
List<List<Symbol>> pks = List.<List<Symbol>>of(List.<Symbol>of(Literal.of(1), Literal.of("Ford")));
DocKeys docKeys = new DocKeys(pks, false, false, 1, null);
DocKeys.DocKey key = docKeys.getOnlyKey();
CoordinatorTxnCtx txnCtx = CoordinatorTxnCtx.systemTransactionContext();
assertThat(key.getRouting(txnCtx, nodeCtx, Row.EMPTY, SubQueryResults.EMPTY), is("Ford"));
assertThat(key.getId(txnCtx, nodeCtx, Row.EMPTY, SubQueryResults.EMPTY), is("AgRGb3JkATE="));
}
use of io.crate.metadata.CoordinatorTxnCtx in project crate by crate.
the class DocIndexMetadataTest method getDocIndexMetadataFromStatement.
private DocIndexMetadata getDocIndexMetadataFromStatement(String stmt) throws IOException {
Statement statement = SqlParser.createStatement(stmt);
DocTableInfoFactory docTableInfoFactory = new InternalDocTableInfoFactory(nodeCtx, new IndexNameExpressionResolver());
ViewInfoFactory viewInfoFactory = (ident, state) -> null;
DocSchemaInfo docSchemaInfo = new DocSchemaInfo(Schemas.DOC_SCHEMA_NAME, clusterService, nodeCtx, udfService, viewInfoFactory, docTableInfoFactory);
Path homeDir = createTempDir();
Schemas schemas = new Schemas(Map.of("doc", docSchemaInfo), clusterService, new DocSchemaInfoFactory(docTableInfoFactory, viewInfoFactory, nodeCtx, udfService));
FulltextAnalyzerResolver fulltextAnalyzerResolver = new FulltextAnalyzerResolver(clusterService, new AnalysisRegistry(new Environment(Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), homeDir.toString()).build(), homeDir.resolve("config")), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
CreateTableStatementAnalyzer analyzer = new CreateTableStatementAnalyzer(nodeCtx);
Analysis analysis = new Analysis(new CoordinatorTxnCtx(SessionContext.systemSessionContext()), ParamTypeHints.EMPTY);
CoordinatorTxnCtx txnCtx = new CoordinatorTxnCtx(SessionContext.systemSessionContext());
AnalyzedCreateTable analyzedCreateTable = analyzer.analyze((CreateTable<Expression>) statement, analysis.paramTypeHints(), analysis.transactionContext());
BoundCreateTable analyzedStatement = CreateTablePlan.bind(analyzedCreateTable, txnCtx, nodeCtx, Row.EMPTY, SubQueryResults.EMPTY, new NumberOfShards(clusterService), schemas, fulltextAnalyzerResolver);
Settings.Builder settingsBuilder = Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.version.created", org.elasticsearch.Version.CURRENT).put(analyzedStatement.tableParameter().settings());
IndexMetadata indexMetadata = IndexMetadata.builder(analyzedStatement.tableIdent().name()).settings(settingsBuilder).putMapping(new MappingMetadata(Constants.DEFAULT_MAPPING_TYPE, analyzedStatement.mapping())).build();
return newMeta(indexMetadata, analyzedStatement.tableIdent().name());
}
Aggregations