Skip to content

Commit ada129e

Browse files
georgeajitgeorgeajit
authored andcommitted
New tests for columninfo in api
1 parent 516ad8e commit ada129e

File tree

2 files changed

+100
-4
lines changed

2 files changed

+100
-4
lines changed

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestOpticOnLiterals.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,28 @@ public void testFacetByWithBucketGroups() throws KeyManagementException, NoSuchA
19571957
}
19581958
}
19591959

1960-
@AfterClass
1960+
@Test
1961+
public void testLiteralsWithColumnInfo() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException {
1962+
System.out.println("In testLiteralsWithColumnInfo method");
1963+
1964+
// Create a new Plan.
1965+
RowManager rowMgr = client.newRowManager();
1966+
PlanBuilder p = rowMgr.newPlanBuilder();
1967+
1968+
// plans from literals
1969+
ModifyPlan plan1 = p.fromLiterals(literals1);
1970+
ModifyPlan plan2 = p.fromLiterals(literals2);
1971+
ModifyPlan output = plan1.joinInner(plan2).orderBy(p.asc(p.col("rowId")));
1972+
1973+
String colInfo = rowMgr.columnInfoAs(output, String.class);
1974+
//System.out.println("In testLiteralsWithColumnInfo method" + colInfo);
1975+
assertTrue("Element 1 desc value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"desc\", \"type\":\"unknown\", \"nullable\":false"));
1976+
assertTrue("Element 2 colorId value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"colorId\", \"type\":\"unknown\", \"nullable\":false}"));
1977+
assertTrue("Element 3 rowId value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"rowId\", \"type\":\"unknown\", \"nullable\":false}"));
1978+
assertTrue("Element 4 colorDesc value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"colorDesc\", \"type\":\"unknown\", \"nullable\":false}"));
1979+
}
1980+
1981+
@AfterClass
19611982
public static void tearDownAfterClass() throws Exception
19621983
{
19631984
System.out.println("In tear down");

marklogic-client-api-functionaltests/src/test/java/com/marklogic/client/functionaltest/TestOpticOnViews.java

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 MarkLogic Corporation
2+
* Copyright (c) 2021 MarkLogic Corporation
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1463,7 +1463,7 @@ public void testjoinInnerWithDataTypes() throws KeyManagementException, NoSuchAl
14631463
}
14641464

14651465
/*
1466-
* This test checks plan builder with invlid Schema and view names.
1466+
* This test checks plan builder with invalid Schema and view names.
14671467
*/
14681468
@Test
14691469
public void testinValidNamedSchemaView() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException {
@@ -3082,13 +3082,88 @@ public void testFacetByWithBindParams() throws KeyManagementException, NoSuchAlg
30823082

30833083
rowMgr.resultDoc(output, jacksonHandleFrg);
30843084
JsonNode jsonResultsFrag = jacksonHandleFrg.get();
3085-
System.out.println("Results are " + jsonResultsFrag);
3085+
//System.out.println("Results are " + jsonResultsFrag);
30863086

30873087
JsonNode jsonColumnsResults = jsonResultsFrag.get("columns");
30883088
assertEquals("Facet Nodes group name value incorrect ", "group0", jsonColumnsResults.get(0).get("name").asText());
30893089
assertEquals("Facet Nodes group name value incorrect ", "group1", jsonColumnsResults.get(1).get("name").asText());
30903090
}
30913091

3092+
// Testing columnInfo - similar to testgroupBy
3093+
3094+
@Test
3095+
public void testColumnInfo() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException {
3096+
System.out.println("In testColumnInfo method");
3097+
RowManager rowMgr = client.newRowManager();
3098+
PlanBuilder p = rowMgr.newPlanBuilder();
3099+
3100+
ModifyPlan plan1 = p.fromView("opticFunctionalTest", "detail")
3101+
.orderBy(p.schemaCol("opticFunctionalTest", "detail", "id"));
3102+
3103+
ModifyPlan plan2 = p.fromView("opticFunctionalTest", "master")
3104+
.orderBy(p.schemaCol("opticFunctionalTest", "master", "id"));
3105+
ModifyPlan plan3 = plan1.union(plan2)
3106+
.select(p.as("MasterName", p.schemaCol("opticFunctionalTest", "master", "name")),
3107+
p.schemaCol("opticFunctionalTest", "master", "date"),
3108+
p.as("DetailName", p.schemaCol("opticFunctionalTest", "detail", "name")),
3109+
p.col("amount"),
3110+
p.col("color")
3111+
)
3112+
.orderBy(p.desc(p.col("MasterName")));
3113+
String colInfo = rowMgr.columnInfoAs(plan3, String.class);
3114+
//System.out.println("In testColumnInfo method" + colInfo);
3115+
// Should have 5 nodes returned.
3116+
assertTrue("Element 1 MasterName value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"MasterName\", \"type\":\"string\", \"nullable\":true}"));
3117+
assertTrue("Element 2 master value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"master\", \"column\":\"date\", \"type\":\"date\", \"nullable\":true}"));
3118+
assertTrue("Element 3 DetailName value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"DetailName\", \"type\":\"string\", \"nullable\":true}"));
3119+
assertTrue("Element 4 amount value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"detail\", \"column\":\"amount\", \"type\":\"double\", \"nullable\":true}"));
3120+
assertTrue("Element 5 color value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"detail\", \"column\":\"color\", \"type\":\"string\", \"nullable\":true}"));
3121+
}
3122+
3123+
// Test for fragment Id types. Similar to testExplainPlan
3124+
@Test
3125+
public void testColInfoWithSysCols() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException {
3126+
System.out.println("In testColInfoWithSysCols method");
3127+
3128+
// Create a new Plan.
3129+
RowManager rowMgr = client.newRowManager();
3130+
PlanBuilder p = rowMgr.newPlanBuilder();
3131+
3132+
PlanSystemColumn fIdCol1 = p.fragmentIdCol("fragIdCol1");
3133+
PlanSystemColumn fIdCol2 = p.fragmentIdCol("fragIdCol2");
3134+
3135+
ModifyPlan plan1 = p.fromView("opticFunctionalTest", "detail", null, fIdCol1)
3136+
.orderBy(p.col("id"));
3137+
ModifyPlan plan2 = p.fromView("opticFunctionalTest", "master", null, fIdCol2)
3138+
.orderBy(p.schemaCol("opticFunctionalTest", "master", "id"));
3139+
3140+
ModifyPlan output = plan1.joinInner(plan2).where(
3141+
p.eq(
3142+
p.schemaCol("opticFunctionalTest", "master", "id"),
3143+
p.col("masterId")
3144+
)
3145+
)
3146+
.select(
3147+
p.as("MasterName", p.schemaCol("opticFunctionalTest", "master", "name")),
3148+
p.schemaCol("opticFunctionalTest", "master", "date"),
3149+
p.as("DetailName", p.schemaCol("opticFunctionalTest", "detail", "name")),
3150+
p.col("amount"),
3151+
p.col("color"),
3152+
fIdCol1,
3153+
fIdCol2
3154+
)
3155+
.orderBy(p.desc(p.col("DetailName")));
3156+
String colInfo = rowMgr.columnInfoAs(output, String.class);
3157+
// Should have 7 nodes returned.
3158+
assertTrue("Element 1 MasterName value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"MasterName\", \"type\":\"string\", \"nullable\":false}"));
3159+
assertTrue("Element 2 master value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"master\", \"column\":\"date\", \"type\":\"date\", \"nullable\":false}"));
3160+
assertTrue("Element 3 DetailName value incorrect", colInfo.contains("{\"schema\":\"\", \"view\":\"\", \"column\":\"DetailName\", \"type\":\"string\", \"nullable\":false}"));
3161+
assertTrue("Element 4 detail-double value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"detail\", \"column\":\"amount\", \"type\":\"double\", \"nullable\":false}"));
3162+
assertTrue("Element 5 detail-string value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"detail\", \"column\":\"color\", \"type\":\"string\", \"nullable\":false}"));
3163+
assertTrue("Element 6 detail-unknown value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"detail\", \"column\":\"fragIdCol1\", \"type\":\"unknown\", \"nullable\":false}"));
3164+
assertTrue("Element 7 master-unknown value incorrect", colInfo.contains("{\"schema\":\"opticFunctionalTest\", \"view\":\"master\", \"column\":\"fragIdCol2\", \"type\":\"unknown\", \"nullable\":false}"));
3165+
}
3166+
30923167
@AfterClass
30933168
public static void tearDownAfterClass() throws Exception {
30943169
System.out.println("In tear down");

0 commit comments

Comments
 (0)