Skip to content

Commit

Permalink
Merge pull request #78 from dcrissman/Join-NeedDistrict
Browse files Browse the repository at this point in the history
fix Join needDistinct and add unit test
  • Loading branch information
jewzaam committed Nov 12, 2014
2 parents 64df883 + 928f50e commit 086814c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
*/
package com.redhat.lightblue.metadata.rdbms.model;

import com.redhat.lightblue.metadata.parser.MetadataParser;
import com.redhat.lightblue.metadata.rdbms.converter.SimpleConverter;
import com.redhat.lightblue.common.rdbms.RDBMSConstants;
import java.util.ArrayList;
import java.util.List;

import com.redhat.lightblue.common.rdbms.RDBMSConstants;
import com.redhat.lightblue.metadata.parser.MetadataParser;
import com.redhat.lightblue.metadata.rdbms.converter.SimpleConverter;

/**
*
* @author lcestari
Expand All @@ -42,16 +43,14 @@ public <T> void parse(MetadataParser<T> p, T t) {
String jts = p.getStringProperty(t, "joinTablesStatement");
Object needDistinct1 = p.getValueProperty(t, "needDistinct");
if(needDistinct1 != null) {
Boolean needDistinct = (Boolean) needDistinct1;
this.needDistinct = (Boolean) needDistinct1;
}
List<T> pmsT = p.getObjectList(t, "projectionMappings");
List<ProjectionMapping> pms = parseProjectionMappings(p, pmsT);

this.tables = ts;
this.joinTablesStatement = jts;
this.projectionMappings = pms;
this.needDistinct = needDistinct;

}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.redhat.lightblue.metadata.rdbms.model;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.junit.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.redhat.lightblue.metadata.parser.Extensions;
import com.redhat.lightblue.metadata.parser.JSONMetadataParser;
import com.redhat.lightblue.metadata.parser.MetadataParser;
import com.redhat.lightblue.metadata.types.DefaultTypes;
import com.redhat.lightblue.util.JsonUtils;

public class JoinTest {

@Test
public void testParse_DistinctTrue() throws IOException{
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));

JsonNode node = JsonUtils.json("{\"tables\":[{\"name\":\"tname\"}],\"needDistinct\":true,\"projectionMappings\":[{\"column\":\"c\",\"field\":\"f\"}]}");

Join join = new Join();
join.parse(p, node);

assertTrue(join.isNeedDistinct());
}

@Test
public void testParse_DistinctFalse() throws IOException{
MetadataParser<JsonNode> p = new JSONMetadataParser(
new Extensions<JsonNode>(),
new DefaultTypes(),
new JsonNodeFactory(true));

JsonNode node = JsonUtils.json("{\"tables\":[{\"name\":\"tname\"}],\"needDistinct\":false,\"projectionMappings\":[{\"column\":\"c\",\"field\":\"f\"}]}");

Join join = new Join();
join.parse(p, node);

assertFalse(join.isNeedDistinct());
}

}

0 comments on commit 086814c

Please sign in to comment.