Search in sources :

Example 1 with ClusteredBy

use of io.crate.sql.tree.ClusteredBy in project crate by crate.

the class CreateBlobTableAnalyzer method analyze.

public CreateBlobTableAnalyzedStatement analyze(CreateBlobTable node, ParameterContext parameterContext) {
    CreateBlobTableAnalyzedStatement statement = new CreateBlobTableAnalyzedStatement();
    TableIdent tableIdent = BlobTableAnalyzer.tableToIdent(node.name());
    statement.table(tableIdent, schemas);
    int numShards;
    Optional<ClusteredBy> clusteredBy = node.clusteredBy();
    if (clusteredBy.isPresent()) {
        numShards = numberOfShards.fromClusteredByClause(clusteredBy.get(), parameterContext.parameters());
    } else {
        numShards = numberOfShards.defaultNumberOfShards();
    }
    statement.tableParameter().settingsBuilder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards);
    // apply default in case it is not specified in the genericProperties,
    // if it is it will get overwritten afterwards.
    TablePropertiesAnalyzer.analyze(statement.tableParameter(), new BlobTableParameterInfo(), node.genericProperties(), parameterContext.parameters(), true);
    return statement;
}
Also used : ClusteredBy(io.crate.sql.tree.ClusteredBy) TableIdent(io.crate.metadata.TableIdent)

Example 2 with ClusteredBy

use of io.crate.sql.tree.ClusteredBy in project crate by crate.

the class NumberOfShardsTest method testGetNumberOfShards.

@Test
public void testGetNumberOfShards() {
    ClusteredBy clusteredBy = new ClusteredBy(Optional.of(QNAME_REF), Optional.of(LongLiteral.fromObject(7)));
    assertThat(numberOfShards.fromClusteredByClause(clusteredBy, Row.EMPTY), is(7));
}
Also used : ClusteredBy(io.crate.sql.tree.ClusteredBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with ClusteredBy

use of io.crate.sql.tree.ClusteredBy in project crate by crate.

the class NumberOfShardsTest method testGetNumberOfShardsLessThanOne.

@Test
public void testGetNumberOfShardsLessThanOne() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("num_shards in CLUSTERED clause must be greater than 0");
    numberOfShards.fromClusteredByClause(new ClusteredBy(Optional.of(QNAME_REF), Optional.of(LongLiteral.fromObject(0))), Row.EMPTY);
}
Also used : ClusteredBy(io.crate.sql.tree.ClusteredBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

ClusteredBy (io.crate.sql.tree.ClusteredBy)3 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 Test (org.junit.Test)2 TableIdent (io.crate.metadata.TableIdent)1