Skip to content

Commit dacf117

Browse files
llingllinggit
authored andcommitted
#1329 expose op.columnInfo
1 parent 8c30f2d commit dacf117

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/impl/RowManagerImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,30 @@ public <T> T generateViewAs(Plan plan, String schema, String view, Class<T> as)
285285
return handle.get();
286286
}
287287

288+
@Override
289+
public <T extends JSONReadHandle> T columnInfo(Plan plan, T resultsHandle) {
290+
if (resultsHandle == null) {
291+
throw new IllegalArgumentException("Must specify a handle to generate a view for the plan");
292+
}
293+
294+
PlanBuilderBaseImpl.RequestPlan requestPlan = checkPlan(plan);
295+
AbstractWriteHandle astHandle = requestPlan.getHandle();
296+
297+
RequestParameters params = new RequestParameters();
298+
params.add("output", "columnInfo");
299+
300+
return services.postResource(requestLogger, "rows", null, params, astHandle, resultsHandle);
301+
}
302+
@Override
303+
public <T> T columnInfoAs(Plan plan, Class<T> as) {
304+
ContentHandle<T> handle = handleFor(as);
305+
if (columnInfo(plan, (JSONReadHandle) handle) == null) {
306+
return null;
307+
}
308+
309+
return handle.get();
310+
}
311+
288312
private void addDatatypeStyleParam(RequestParameters params, RowSetPart datatypeStyle) {
289313
if (datatypeStyle != null) {
290314
switch (datatypeStyle) {

marklogic-client-api/src/main/java/com/marklogic/client/row/RowManager.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.marklogic.client.io.marker.StructureReadHandle;
2323
import com.marklogic.client.io.marker.TextWriteHandle;
2424
import com.marklogic.client.io.marker.XMLReadHandle;
25+
import com.marklogic.client.io.marker.JSONReadHandle;
2526

2627
/**
2728
* A Row Manager provides database operations on rows projected from documents.
@@ -294,4 +295,32 @@ public enum RowStructure{ARRAY, OBJECT}
294295
* @return an object of the IO class with the content of the generated view for the plan
295296
*/
296297
<T> T generateViewAs(Plan plan, String schema, String view, Class<T> as);
298+
299+
/**
300+
* This function can be used to inspect the state of a plan before execution. It returns the information about each
301+
* column in the plan, including schema name, view name, column name, data type and nullability. It also returns the
302+
* information about system columns.
303+
*
304+
* @param plan the definition of a plan for database rows
305+
* @param handle the Json handle on the column information for the plan
306+
* @param <T> the type of the handle for the column information
307+
* @return the handle with the content of the column information for the plan
308+
*/
309+
<T extends JSONReadHandle> T columnInfo(Plan plan, T handle);
310+
/**This function can be used to inspect the state of a plan before execution. It returns the information about each
311+
* column in the plan, including schema name, view name, column name, data type and nullability. It also returns the
312+
* information about system columns.Generates generates a view that encapsulates a plan.
313+
*
314+
* The IO class must have been registered before creating the database client.
315+
* By default, the provided handles that implement
316+
* {@link com.marklogic.client.io.marker.ContentHandle ContentHandle} are registered.
317+
*
318+
* <a href="../../../../overview-summary.html#ShortcutMethods">Learn more about shortcut methods</a>
319+
*
320+
* @param plan the definition of a plan for database rows
321+
* @param as the IO class for reading the column information for the plan
322+
* @param <T> the type of the IO object for reading the column information
323+
* @return an object of the IO class with the content of the column information for the plan
324+
*/
325+
<T> T columnInfoAs(Plan plan, Class<T> as);
297326
}

marklogic-client-api/src/test/java/com/marklogic/client/test/RowManagerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import javax.xml.transform.stream.StreamResult;
4040
import javax.xml.xpath.XPathExpressionException;
4141

42+
import com.marklogic.client.io.marker.JSONReadHandle;
4243
import com.marklogic.client.row.*;
4344
import com.marklogic.client.type.*;
4445
import org.junit.AfterClass;
@@ -1205,6 +1206,27 @@ public void testMapper() throws IOException, XPathExpressionException {
12051206
}
12061207
}
12071208
@Test
1209+
public void testColumnInfo() throws IOException {
1210+
RowManager rowMgr = Common.client.newRowManager();
1211+
1212+
PlanBuilder p = rowMgr.newPlanBuilder();
1213+
1214+
PlanBuilder.ExportablePlan builtPlan =
1215+
p.fromView("opticUnitTest", "musician")
1216+
.where(
1217+
p.cts.andQuery(
1218+
p.cts.jsonPropertyWordQuery("instrument", "trumpet"),
1219+
p.cts.jsonPropertyWordQuery(p.xs.string("lastName"), p.xs.stringSeq("Armstrong", "Davis"))
1220+
)
1221+
)
1222+
.orderBy(p.col("lastName"));
1223+
1224+
String result = rowMgr.columnInfo(builtPlan, new StringHandle()).get();
1225+
assertNotNull(result);
1226+
result = rowMgr.columnInfoAs(builtPlan, String.class);
1227+
assertNotNull(result);
1228+
}
1229+
@Test
12081230
public void testGenerateView() throws IOException {
12091231
RowManager rowMgr = Common.client.newRowManager();
12101232

0 commit comments

Comments
 (0)