|
1 | 1 | /* |
2 | | - * Copyright (c) 2019 MarkLogic Corporation |
| 2 | + * Copyright (c) 2021 MarkLogic Corporation |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -1463,7 +1463,7 @@ public void testjoinInnerWithDataTypes() throws KeyManagementException, NoSuchAl |
1463 | 1463 | } |
1464 | 1464 |
|
1465 | 1465 | /* |
1466 | | - * This test checks plan builder with invlid Schema and view names. |
| 1466 | + * This test checks plan builder with invalid Schema and view names. |
1467 | 1467 | */ |
1468 | 1468 | @Test |
1469 | 1469 | public void testinValidNamedSchemaView() throws KeyManagementException, NoSuchAlgorithmException, IOException, SAXException, ParserConfigurationException { |
@@ -3082,13 +3082,88 @@ public void testFacetByWithBindParams() throws KeyManagementException, NoSuchAlg |
3082 | 3082 |
|
3083 | 3083 | rowMgr.resultDoc(output, jacksonHandleFrg); |
3084 | 3084 | JsonNode jsonResultsFrag = jacksonHandleFrg.get(); |
3085 | | - System.out.println("Results are " + jsonResultsFrag); |
| 3085 | + //System.out.println("Results are " + jsonResultsFrag); |
3086 | 3086 |
|
3087 | 3087 | JsonNode jsonColumnsResults = jsonResultsFrag.get("columns"); |
3088 | 3088 | assertEquals("Facet Nodes group name value incorrect ", "group0", jsonColumnsResults.get(0).get("name").asText()); |
3089 | 3089 | assertEquals("Facet Nodes group name value incorrect ", "group1", jsonColumnsResults.get(1).get("name").asText()); |
3090 | 3090 | } |
3091 | 3091 |
|
| 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 | + |
3092 | 3167 | @AfterClass |
3093 | 3168 | public static void tearDownAfterClass() throws Exception { |
3094 | 3169 | System.out.println("In tear down"); |
|
0 commit comments