mirror of https://github.com/apache/druid.git
better error messaging when parseSpec is missing timestampSpec or dimensionSpec (#5439)
This commit is contained in:
parent
8f07a39af7
commit
d159a4fa01
|
@ -22,6 +22,7 @@ package io.druid.data.input.impl;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import io.druid.guice.annotations.ExtensionPoint;
|
import io.druid.guice.annotations.ExtensionPoint;
|
||||||
import io.druid.guice.annotations.PublicApi;
|
import io.druid.guice.annotations.PublicApi;
|
||||||
import io.druid.java.util.common.parsers.Parser;
|
import io.druid.java.util.common.parsers.Parser;
|
||||||
|
@ -47,8 +48,8 @@ public abstract class ParseSpec
|
||||||
|
|
||||||
protected ParseSpec(TimestampSpec timestampSpec, DimensionsSpec dimensionsSpec)
|
protected ParseSpec(TimestampSpec timestampSpec, DimensionsSpec dimensionsSpec)
|
||||||
{
|
{
|
||||||
this.timestampSpec = timestampSpec;
|
this.timestampSpec = Preconditions.checkNotNull(timestampSpec, "parseSpec requires timestampSpec");
|
||||||
this.dimensionsSpec = dimensionsSpec;
|
this.dimensionsSpec = Preconditions.checkNotNull(dimensionsSpec, "parseSpec requires dimensionSpec");
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
|
|
@ -21,13 +21,18 @@ package io.druid.data.input.impl;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import io.druid.java.util.common.parsers.ParseException;
|
import io.druid.java.util.common.parsers.ParseException;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class ParseSpecTest
|
public class ParseSpecTest
|
||||||
{
|
{
|
||||||
|
@Rule
|
||||||
|
public ExpectedException expectedException = ExpectedException.none();
|
||||||
|
|
||||||
@Test(expected = ParseException.class)
|
@Test(expected = ParseException.class)
|
||||||
public void testDuplicateNames() throws Exception
|
public void testDuplicateNames() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -96,4 +101,46 @@ public class ParseSpecTest
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultTimestampSpec() throws Exception
|
||||||
|
{
|
||||||
|
expectedException.expect(NullPointerException.class);
|
||||||
|
expectedException.expectMessage("parseSpec requires timestampSpec");
|
||||||
|
@SuppressWarnings("unused") // expected exception
|
||||||
|
final ParseSpec spec = new DelimitedParseSpec(
|
||||||
|
null,
|
||||||
|
new DimensionsSpec(
|
||||||
|
DimensionsSpec.getDefaultSchemas(Collections.singletonList("a")),
|
||||||
|
Lists.newArrayList("B", "B"),
|
||||||
|
Lists.<SpatialDimensionSchema>newArrayList()
|
||||||
|
),
|
||||||
|
",",
|
||||||
|
null,
|
||||||
|
Arrays.asList("a", "B"),
|
||||||
|
false,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDimensionSpecRequired() throws Exception
|
||||||
|
{
|
||||||
|
expectedException.expect(NullPointerException.class);
|
||||||
|
expectedException.expectMessage("parseSpec requires dimensionSpec");
|
||||||
|
@SuppressWarnings("unused") // expected exception
|
||||||
|
final ParseSpec spec = new DelimitedParseSpec(
|
||||||
|
new TimestampSpec(
|
||||||
|
"timestamp",
|
||||||
|
"auto",
|
||||||
|
null
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
",",
|
||||||
|
null,
|
||||||
|
Arrays.asList("a", "B"),
|
||||||
|
false,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue