chengchengpei closed pull request #6072: validate baseDataSource non-empty 
string in DerivativeDataSourceMetad…
URL: https://github.com/apache/incubator-druid/pull/6072
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
 
b/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
index ed102e354e0..3a82672e14d 100644
--- 
a/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
+++ 
b/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
@@ -23,6 +23,7 @@
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
+import com.google.common.base.Strings;
 import io.druid.indexing.overlord.DataSourceMetadata;
 
 import java.util.Objects;
@@ -41,7 +42,9 @@ public DerivativeDataSourceMetadata(
       @JsonProperty("metrics") Set<String> metrics
   )
   {
-    this.baseDataSource = Preconditions.checkNotNull(baseDataSource, 
"baseDataSource cannot be null. This is not a valid 
DerivativeDataSourceMetadata.");
+    Preconditions.checkArgument(!Strings.isNullOrEmpty(baseDataSource), 
"baseDataSource cannot be null or empty. Please provide a baseDataSource.");
+    this.baseDataSource = baseDataSource;
+
     this.dimensions = Preconditions.checkNotNull(dimensions, "dimensions 
cannot be null. This is not a valid DerivativeDataSourceMetadata.");
     this.metrics = Preconditions.checkNotNull(metrics, "metrics cannot be 
null. This is not a valid DerivativeDataSourceMetadata.");
   }
diff --git 
a/extensions-contrib/materialized-view-maintenance/src/test/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadataTest.java
 
b/extensions-contrib/materialized-view-maintenance/src/test/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadataTest.java
new file mode 100644
index 00000000000..d62ea385d31
--- /dev/null
+++ 
b/extensions-contrib/materialized-view-maintenance/src/test/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadataTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.druid.indexing.materializedview;
+
+import com.google.common.collect.Sets;
+import org.hamcrest.CoreMatchers;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.util.Set;
+
+
+public class DerivativeDataSourceMetadataTest
+{
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Test
+  public void testEmptyBaseDataSource() throws Exception
+  {
+    
expectedException.expect(CoreMatchers.instanceOf(IllegalArgumentException.class));
+    expectedException.expectMessage(
+        "baseDataSource cannot be null or empty. Please provide a 
baseDataSource."
+    );
+    String baseDataSource = "";
+    Set<String> dims = Sets.newHashSet("dim1", "dim2", "dim3");
+    Set<String> metrics = Sets.newHashSet("cost");
+    DerivativeDataSourceMetadata metadata = new 
DerivativeDataSourceMetadata(baseDataSource, dims, metrics);
+  }
+
+  @Test
+  public void testNullBaseDataSource() throws Exception
+  {
+    
expectedException.expect(CoreMatchers.instanceOf(IllegalArgumentException.class));
+    expectedException.expectMessage(
+        "baseDataSource cannot be null or empty. Please provide a 
baseDataSource."
+    );
+    String baseDataSource = null;
+    Set<String> dims = Sets.newHashSet("dim1", "dim2", "dim3");
+    Set<String> metrics = Sets.newHashSet("cost");
+    DerivativeDataSourceMetadata metadata = new 
DerivativeDataSourceMetadata(baseDataSource, dims, metrics);
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to