Search in sources :

Example 11 with ArbitraryGranularitySpec

use of org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class IndexTaskTest method testWithArbitraryGranularity.

@Test
public void testWithArbitraryGranularity() throws Exception {
    File tmpDir = temporaryFolder.newFolder();
    File tmpFile = File.createTempFile("druid", "index", tmpDir);
    try (BufferedWriter writer = Files.newWriter(tmpFile, StandardCharsets.UTF_8)) {
        writer.write("2014-01-01T00:00:10Z,a,1\n");
        writer.write("2014-01-01T01:00:20Z,b,1\n");
        writer.write("2014-01-01T02:00:30Z,c,1\n");
    }
    IndexTask indexTask = new IndexTask(null, null, createDefaultIngestionSpec(jsonMapper, tmpDir, new ArbitraryGranularitySpec(Granularities.MINUTE, Collections.singletonList(Intervals.of("2014-01-01/2014-01-02"))), null, createTuningConfigWithMaxRowsPerSegment(10, true), false, false), null);
    final List<DataSegment> segments = runTask(indexTask).rhs;
    Assert.assertEquals(1, segments.size());
}
Also used : File(java.io.File) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec) DataSegment(org.apache.druid.timeline.DataSegment) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 12 with ArbitraryGranularitySpec

use of org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class ParallelIndexTestingFactory method createDataSchema.

static DataSchema createDataSchema(List<Interval> granularitySpecInputIntervals) {
    GranularitySpec granularitySpec = new ArbitraryGranularitySpec(Granularities.DAY, granularitySpecInputIntervals);
    TimestampSpec timestampSpec = new TimestampSpec(SCHEMA_TIME, "auto", null);
    DimensionsSpec dimensionsSpec = new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of(SCHEMA_DIMENSION)));
    return new DataSchema(DATASOURCE, timestampSpec, dimensionsSpec, new AggregatorFactory[] {}, granularitySpec, TransformSpec.NONE, null, NESTED_OBJECT_MAPPER);
}
Also used : DataSchema(org.apache.druid.segment.indexing.DataSchema) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec) GranularitySpec(org.apache.druid.segment.indexing.granularity.GranularitySpec) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec)

Example 13 with ArbitraryGranularitySpec

use of org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class SeekableStreamIndexTaskRunnerAuthTest method setUp.

@Before
public void setUp() {
    // Create an AuthorizerMapper that only allows access to a Datasource resource
    AuthorizerMapper authorizerMapper = new AuthorizerMapper(null) {

        @Override
        public Authorizer getAuthorizer(String name) {
            return (authenticationResult, resource, action) -> {
                final String username = authenticationResult.getIdentity();
                // - or, Datasource Write User requests Write access
                if (resource.getType().equals(ResourceType.DATASOURCE)) {
                    return new Access((action == Action.READ && username.equals(Users.DATASOURCE_READ)) || (action == Action.WRITE && username.equals(Users.DATASOURCE_WRITE)));
                }
                // Do not allow access to any other resource
                return new Access(false);
            };
        }
    };
    DataSchema dataSchema = new DataSchema("datasource", new TimestampSpec(null, null, null), new DimensionsSpec(Collections.emptyList()), new AggregatorFactory[] {}, new ArbitraryGranularitySpec(new AllGranularity(), Collections.emptyList()), TransformSpec.NONE, null, null);
    SeekableStreamIndexTaskTuningConfig tuningConfig = mock(SeekableStreamIndexTaskTuningConfig.class);
    SeekableStreamIndexTaskIOConfig<String, String> ioConfig = new TestSeekableStreamIndexTaskIOConfig();
    // Initiliaze task and task runner
    SeekableStreamIndexTask<String, String, ByteEntity> indexTask = new TestSeekableStreamIndexTask("id", dataSchema, tuningConfig, ioConfig);
    taskRunner = new TestSeekableStreamIndexTaskRunner(indexTask, authorizerMapper);
}
Also used : TaskToolbox(org.apache.druid.indexing.common.TaskToolbox) StreamPartition(org.apache.druid.indexing.seekablestream.common.StreamPartition) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec) RecordSupplier(org.apache.druid.indexing.seekablestream.common.RecordSupplier) OrderedPartitionableRecord(org.apache.druid.indexing.seekablestream.common.OrderedPartitionableRecord) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) EasyMock.mock(org.easymock.EasyMock.mock) AllGranularity(org.apache.druid.java.util.common.granularity.AllGranularity) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) ForbiddenException(org.apache.druid.server.security.ForbiddenException) EasyMock.replay(org.easymock.EasyMock.replay) AuthConfig(org.apache.druid.server.security.AuthConfig) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ExpectedException(org.junit.rules.ExpectedException) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Before(org.junit.Before) DateTimes(org.apache.druid.java.util.common.DateTimes) Access(org.apache.druid.server.security.Access) ResourceType(org.apache.druid.server.security.ResourceType) AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) CsvInputFormat(org.apache.druid.data.input.impl.CsvInputFormat) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) Test(org.junit.Test) Action(org.apache.druid.server.security.Action) EasyMock(org.easymock.EasyMock) LockGranularity(org.apache.druid.indexing.common.LockGranularity) OrderedSequenceNumber(org.apache.druid.indexing.seekablestream.common.OrderedSequenceNumber) Consumer(java.util.function.Consumer) List(java.util.List) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) ByteEntity(org.apache.druid.data.input.impl.ByteEntity) DataSchema(org.apache.druid.segment.indexing.DataSchema) Collections(java.util.Collections) TransformSpec(org.apache.druid.segment.transform.TransformSpec) Authorizer(org.apache.druid.server.security.Authorizer) ByteEntity(org.apache.druid.data.input.impl.ByteEntity) AllGranularity(org.apache.druid.java.util.common.granularity.AllGranularity) Access(org.apache.druid.server.security.Access) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec) DataSchema(org.apache.druid.segment.indexing.DataSchema) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) Before(org.junit.Before)

Example 14 with ArbitraryGranularitySpec

use of org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class DataSchemaTest method testDefaultExclusions.

@Test
public void testDefaultExclusions() {
    Map<String, Object> parser = jsonMapper.convertValue(new StringInputRowParser(new JSONParseSpec(new TimestampSpec("time", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(ImmutableList.of("dimB", "dimA"))), null, null, null), null), JacksonUtils.TYPE_REFERENCE_MAP_STRING_OBJECT);
    DataSchema schema = new DataSchema(IdUtilsTest.VALID_ID_CHARS, parser, new AggregatorFactory[] { new DoubleSumAggregatorFactory("metric1", "col1"), new DoubleSumAggregatorFactory("metric2", "col2") }, new ArbitraryGranularitySpec(Granularities.DAY, ImmutableList.of(Intervals.of("2014/2015"))), null, jsonMapper);
    Assert.assertEquals(ImmutableSet.of("__time", "time", "col1", "col2", "metric1", "metric2"), schema.getDimensionsSpec().getDimensionExclusions());
}
Also used : DoubleSumAggregatorFactory(org.apache.druid.query.aggregation.DoubleSumAggregatorFactory) StringInputRowParser(org.apache.druid.data.input.impl.StringInputRowParser) TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) DimensionsSpec(org.apache.druid.data.input.impl.DimensionsSpec) JSONParseSpec(org.apache.druid.data.input.impl.JSONParseSpec) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IdUtilsTest(org.apache.druid.common.utils.IdUtilsTest)

Example 15 with ArbitraryGranularitySpec

use of org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec in project druid by druid-io.

the class DataSchemaTest method testOverlapTimeAndDim.

@Test
public void testOverlapTimeAndDim() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Cannot specify a column more than once: [__time] seen in dimensions list, " + "primary timestamp (__time cannot appear as a dimension or metric)");
    DataSchema schema = new DataSchema(IdUtilsTest.VALID_ID_CHARS, new TimestampSpec("time", "auto", null), DimensionsSpec.builder().setDimensions(DimensionsSpec.getDefaultSchemas(ImmutableList.of("__time", "dimA", "dimB", "metric1"))).setDimensionExclusions(ImmutableList.of("dimC")).build(), null, new ArbitraryGranularitySpec(Granularities.DAY, ImmutableList.of(Intervals.of("2014/2015"))), null, null, jsonMapper);
}
Also used : TimestampSpec(org.apache.druid.data.input.impl.TimestampSpec) ArbitraryGranularitySpec(org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test) IdUtilsTest(org.apache.druid.common.utils.IdUtilsTest)

Aggregations

ArbitraryGranularitySpec (org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec)19 Test (org.junit.Test)17 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)15 IdUtilsTest (org.apache.druid.common.utils.IdUtilsTest)11 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)11 JSONParseSpec (org.apache.druid.data.input.impl.JSONParseSpec)10 StringInputRowParser (org.apache.druid.data.input.impl.StringInputRowParser)9 DoubleSumAggregatorFactory (org.apache.druid.query.aggregation.DoubleSumAggregatorFactory)9 DataSchema (org.apache.druid.segment.indexing.DataSchema)7 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)6 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)5 IndexIOConfig (org.apache.druid.indexing.common.task.IndexTask.IndexIOConfig)4 IndexIngestionSpec (org.apache.druid.indexing.common.task.IndexTask.IndexIngestionSpec)4 NoopInputSource (org.apache.druid.data.input.impl.NoopInputSource)3 NoopFirehoseFactory (org.apache.druid.data.input.impl.NoopFirehoseFactory)2 NoopInputFormat (org.apache.druid.data.input.impl.NoopInputFormat)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1