Skip to content

Commit

Permalink
Merge pull request #1624 from marklogic/release/6.4.1
Browse files Browse the repository at this point in the history
Merge release/6.4.1 into master
  • Loading branch information
rjrudin authored Nov 30, 2023
2 parents 045acdc + 843e59c commit 5f4f7a8
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 68 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.marklogic
version=6.4.0
version=6.4.1
describedName=MarkLogic Java Client API
publishUrl=file:../marklogic-java/releases

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.marklogic.client.fastfunctest;

import com.marklogic.client.document.GenericDocumentManager;
import com.marklogic.client.io.SearchHandle;
import com.marklogic.client.query.QueryManager;
import com.marklogic.client.query.StructuredQueryDefinition;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Added in 6.4.1; the 3 methods being tested had been commented out with a comment indicating that the server APIs
* were not fully fleshed out, but those APIs - specifically, how the REST API receives a server timestamp - have long
* been present in the REST API.
*/
public class ReadAndSearchWithTimestampTest extends AbstractFunctionalTest {

@Test
void test() {
final String collection = "timestamp-test";
final String[] uris = writeJsonDocs(2, collection).toArray(new String[]{});

final QueryManager queryManager = client.newQueryManager();
final GenericDocumentManager docManager = client.newDocumentManager();
final StructuredQueryDefinition collectionQuery = queryManager.newStructuredQueryBuilder().collection(collection);

SearchHandle searchResults = queryManager.search(collectionQuery, new SearchHandle());
assertEquals(2, searchResults.getTotalResults());
final long serverTimestamp = searchResults.getServerTimestamp();
logger.info("Server timestamp: " + serverTimestamp);

// Write additional docs to the same collection and verify they are not returned by subsequent point-in-time
// queries. Note that the first 2 URIs are the same as the ones originally written.
writeJsonDocs(5, collection);

// Verify each of the exposed methods in 6.4.1
assertEquals(2, docManager.read(serverTimestamp, uris).size());
assertEquals(2, docManager.read(serverTimestamp, null, uris).size());
assertEquals(2, docManager.search(collectionQuery, 1, serverTimestamp).size());

assertEquals(5, docManager.search(collectionQuery, 1).size(),
"A query without a timestamp should return all of the documents in the collection.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,9 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
* server via getServerTimestamp() on any handle.
* @param uris the database uris identifying documents to retrieve
* @return the DocumentPage of matching documents and metadata
* @since 6.4.1
*/
/* Hide the following for now because the API isn't yet fully fleshed-out
DocumentPage read(long serverTimestamp, String... uris);
*/

/**
* Reads from the database a list of documents matching the provided uris. Allows
Expand All @@ -492,10 +491,9 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
* @param transform the transform to be run on the server on each document (must already be installed)
* @param uris the database uris identifying documents to retrieve
* @return the DocumentPage of matching documents and metadata
* @since 6.4.1
*/
/* Hide the following for now because the API isn't yet fully fleshed-out
DocumentPage read(long serverTimestamp, ServerTransform transform, String... uris);
*/

/**
* Reads from the database a list of documents matching the provided uris. Allows
Expand All @@ -509,23 +507,6 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
*/
DocumentPage read(Transaction transaction, String... uris);

/**
* Reads from the database a list of documents matching the provided uris. Allows
* iteration across matching documents and metadata (only if setMetadataCategories
* has been called to request metadata). To find out how many of your uris matched,
* call the {@link DocumentPage#size() DocumentPage.size()} method.
*
* @param serverTimestamp the point in time at which to read these
* documents. The value must be a merge timestamp obtained from the
* server via getServerTimestamp() on any handle.
* @param transaction the transaction in which this read is participating
* @param uris the database uris identifying documents to retrieve
* @return the DocumentPage of matching documents and metadata
*/
/* Hide the following for now because the API isn't yet fully fleshed-out
DocumentPage read(long serverTimestamp, Transaction transaction, String... uris);
*/

/**
* Reads from the database a list of documents matching the provided uris. Allows
* iteration across matching documents and metadata (only if setMetadataCategories
Expand All @@ -539,24 +520,6 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
*/
DocumentPage read(ServerTransform transform, Transaction transaction, String... uris);

/**
* Reads from the database a list of documents matching the provided uris. Allows
* iteration across matching documents and metadata (only if setMetadataCategories
* has been called to request metadata). To find out how many of your uris matched,
* call the {@link DocumentPage#size() DocumentPage.size()} method.
*
* @param serverTimestamp the point in time at which to read these
* documents. The value must be a merge timestamp obtained from the
* server via getServerTimestamp() on any handle.
* @param transform the transform to be run on the server on each document (must already be installed)
* @param transaction the transaction in which this read is participating
* @param uris the database uris identifying documents to retrieve
* @return the DocumentPage of matching documents and metadata
*/
/* Hide the following for now because the API isn't yet fully fleshed-out
DocumentPage read(long serverTimestamp, ServerTransform transform, Transaction transaction, String... uris);
*/

/**
* Reads from the database the metadata for a list of documents matching the
* provided uris. Allows iteration across the metadata for matching documents
Expand Down Expand Up @@ -619,10 +582,9 @@ <T extends R> T read(DocumentDescriptor desc, DocumentMetadataReadHandle metadat
* documents. The value must be a merge timestamp obtained from the
* server via getServerTimestamp() on any handle.
* @return the DocumentPage of matching documents and metadata
* @since 6.4.1
*/
/* Hide the following for now because the API isn't yet fully fleshed-out
DocumentPage search(SearchQueryDefinition querydef, long start, long serverTimestamp);
*/

/**
* Just like {@link QueryManager#search(SearchQueryDefinition, SearchReadHandle, long, Transaction) QueryManager.search}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ private void addCategoryParams(Set<Metadata> categories, RequestParameters param
}
}
private void addCategoryParam(RequestParameters params, Metadata category) {
addCategoryParam(params, category.name().toLowerCase());
addCategoryParam(params, category.toString().toLowerCase());
}
private void addCategoryParam(RequestParameters params, String category) {
params.add("category", category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import com.marklogic.client.ResourceNotFoundException;
import com.marklogic.client.ResourceNotResendableException;
import com.marklogic.client.admin.QueryOptionsManager;
import com.marklogic.client.document.DocumentManager;
import com.marklogic.client.document.DocumentPage;
import com.marklogic.client.document.DocumentRecord;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.DocumentMetadataHandle;
import com.marklogic.client.io.Format;
import com.marklogic.client.io.SearchHandle;
Expand All @@ -32,17 +36,15 @@
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

public class StringSearchTest {
@SuppressWarnings("unused")
private static final Logger logger = (Logger) LoggerFactory.getLogger(StringSearchTest.class);
private static final Logger logger = LoggerFactory.getLogger(StringSearchTest.class);

@BeforeAll
public static void beforeClass() {
Expand All @@ -54,9 +56,27 @@ public static void beforeClass() {
public static void afterClass() {
}

@Test
void returnDocumentsWithMetadataValues() {
XMLDocumentManager mgr = Common.client.newXMLDocumentManager();
mgr.write("/metadata/test.xml",
new DocumentMetadataHandle().withMetadataValue("hello", "world"),
new StringHandle("<test>metadataabc</test>"));

mgr.setMetadataCategories(DocumentManager.Metadata.METADATAVALUES);

DocumentPage page = mgr.search(Common.client.newQueryManager().newStructuredQueryBuilder().term("metadataabc"), 1);
assertTrue(page.hasNext());

DocumentRecord record = page.next();
assertEquals("/metadata/test.xml", record.getUri());
DocumentMetadataHandle.DocumentMetadataValues values = record.getMetadata(new DocumentMetadataHandle()).getMetadataValues();
assertEquals("world", values.get("hello"));
}

@Test
public void testStringSearch()
throws IOException, ParserConfigurationException, SAXException, FailedRequestException, ForbiddenUserException,
throws FailedRequestException, ForbiddenUserException,
ResourceNotFoundException, ResourceNotResendableException
{
String optionsName = writeOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void fromSparql() {
@Test
public void fromSql() {
verifyExportedPlanReturnsSameRowCount(
op.fromSql("select * from opticUnitTest.musician")
op.fromSql("select * from opticUnitTest.musician_ml10")
);
}

Expand All @@ -103,7 +103,7 @@ public void fromTriples() {
@Test
public void fromView() {
verifyExportedPlanReturnsSameRowCount(
op.fromView("opticUnitTest", "musician"), null
op.fromView("opticUnitTest", "musician_ml10"), null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void deleteNewMusician() {

@Test
void testResultRowsWithPointInTimeQueryTimestamp() {
final RawQueryDSLPlan plan = rowManager.newRawQueryDSLPlan(new StringHandle("op.fromView('opticUnitTest', 'musician')"));
final RawQueryDSLPlan plan = rowManager.newRawQueryDSLPlan(new StringHandle("op.fromView('opticUnitTest', 'musician_ml10')"));

JacksonHandle result = new JacksonHandle();
JsonNode doc = rowManager.resultDoc(plan, result).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class RowManagerTest {
private static RowStructure[] rowstructs = null;
private static RowSetPart[] datatypeStyles = null;

private final static String VIEW_NAME = "musician_ml10";

@SuppressWarnings("unchecked")
@BeforeAll
public static void beforeClass() throws IOException, InterruptedException {
Expand Down Expand Up @@ -452,7 +454,7 @@ public void testView() {
PlanBuilder p = rowMgr.newPlanBuilder();

PlanBuilder.ExportablePlan builtPlan =
p.fromView("opticUnitTest", "musician")
p.fromView("opticUnitTest", VIEW_NAME)
.where(
p.cts.andQuery(
p.cts.jsonPropertyWordQuery("instrument", "trumpet"),
Expand Down Expand Up @@ -484,7 +486,7 @@ public void testSQL() {
RowManager rowMgr = Common.client.newRowManager();
PlanBuilder p = rowMgr.newPlanBuilder();
PlanBuilder.ExportablePlan builtPlan =
p.fromSql("select * from opticUnitTest.musician");
p.fromSql("select * from opticUnitTest.musician_ml10");
int rowNum = 0;
String exception = "";
try {
Expand All @@ -503,7 +505,7 @@ public void testSQL0Result() {
RowManager rowMgr = Common.client.newRowManager();
PlanBuilder p = rowMgr.newPlanBuilder();
PlanBuilder.ExportablePlan builtPlan =
p.fromSql("select * from opticUnitTest.musician where lastName = 'x'");
p.fromSql("select * from opticUnitTest.musician_ml10 where lastName = 'x'");
int rowNum = 0;
String exception = "";
try {
Expand Down Expand Up @@ -564,7 +566,7 @@ public void testSearch() {
PlanBuilder.ExportablePlan builtPlan =
p.fromSearch(p.cts.jsonPropertyValueQuery("instrument", "trumpet"))
.joinInner(
p.fromView("opticUnitTest", "musician", "", viewDocId),
p.fromView("opticUnitTest", VIEW_NAME, "", viewDocId),
p.on(p.fragmentIdCol("fragmentId"), viewDocId)
)
.orderBy(p.col("lastName"));
Expand Down Expand Up @@ -623,7 +625,7 @@ public void testJoinSrcDoc() throws IOException {
PlanBuilder p = rowMgr.newPlanBuilder();

PlanBuilder.ExportablePlan builtPlan =
p.fromView("opticUnitTest", "musician", "", p.fragmentIdCol("musicianDocId"))
p.fromView("opticUnitTest", VIEW_NAME, "", p.fragmentIdCol("musicianDocId"))
.joinDoc(p.col("musicianDoc"), p.fragmentIdCol("musicianDocId"))
.orderBy(p.col("lastName"))
.select(
Expand Down Expand Up @@ -654,7 +656,7 @@ public void testJoinDocUri() throws IOException {
PlanBuilder p = rowMgr.newPlanBuilder();

PlanBuilder.ExportablePlan builtPlan =
p.fromView("opticUnitTest", "musician", "", p.fragmentIdCol("musicianDocId"))
p.fromView("opticUnitTest", VIEW_NAME, "", p.fragmentIdCol("musicianDocId"))
.joinDocUri(p.col("musicianDocUri"), p.fragmentIdCol("musicianDocId"))
.orderBy(p.col("lastName"))
.select(p.col("lastName"), p.col("firstName"), p.col("musicianDocUri"))
Expand Down Expand Up @@ -1286,7 +1288,7 @@ public void testColumnInfo() {
RowManager rowMgr = Common.client.newRowManager();
PlanBuilder p = rowMgr.newPlanBuilder();
PlanBuilder.PreparePlan builtPlan =
p.fromView("opticUnitTest", "musician")
p.fromView("opticUnitTest", VIEW_NAME)
.where(
p.cts.andQuery(
p.cts.jsonPropertyWordQuery("instrument", "trumpet"),
Expand All @@ -1296,10 +1298,10 @@ public void testColumnInfo() {
.orderBy(p.col("lastName"));

String[] expectedColumnInfos = new String[]{
"{\"schema\":\"opticUnitTest\", \"view\":\"musician\", \"column\":\"lastName\", \"type\":\"string\"",
"{\"schema\":\"opticUnitTest\", \"view\":\"musician\", \"column\":\"firstName\", \"type\":\"string\"",
"{\"schema\":\"opticUnitTest\", \"view\":\"musician\", \"column\":\"dob\", \"type\":\"date\"",
"{\"schema\":\"opticUnitTest\", \"view\":\"musician\", \"column\":\"rowid\", \"type\":\"rowid\""
"{\"schema\":\"opticUnitTest\", \"view\":\"musician_ml10\", \"column\":\"lastName\", \"type\":\"string\"",
"{\"schema\":\"opticUnitTest\", \"view\":\"musician_ml10\", \"column\":\"firstName\", \"type\":\"string\"",
"{\"schema\":\"opticUnitTest\", \"view\":\"musician_ml10\", \"column\":\"dob\", \"type\":\"date\"",
"{\"schema\":\"opticUnitTest\", \"view\":\"musician_ml10\", \"column\":\"rowid\", \"type\":\"rowid\""
};

String stringHandleResult = rowMgr.columnInfo(builtPlan, new StringHandle()).get();
Expand All @@ -1317,7 +1319,7 @@ public void testGenerateView() throws IOException {
PlanBuilder p = rowMgr.newPlanBuilder();

PlanBuilder.PreparePlan builtPlan =
p.fromView("opticUnitTest", "musician")
p.fromView("opticUnitTest", VIEW_NAME)
.where(
p.cts.andQuery(
p.cts.jsonPropertyWordQuery("instrument", "trumpet"),
Expand Down Expand Up @@ -1363,7 +1365,7 @@ private DOMHandle initNamespaces(DOMHandle handle) {
@Test
public void testRawSQL() throws IOException {
String plan = "SELECT *\n" +
"FROM opticUnitTest.musician AS ''\n" +
"FROM opticUnitTest.musician_ml10 AS ''\n" +
"WHERE lastName IN ('Armstrong', 'Davis')" +
"ORDER BY lastName;\n";

Expand Down Expand Up @@ -1404,7 +1406,7 @@ public void testRawSPARQLSelect() throws IOException {
@Test
public void testRawQueryDSL() throws IOException {
String plan =
"op.fromView('opticUnitTest', 'musician')\n" +
"op.fromView('opticUnitTest', 'musician_ml10')\n" +
" .where(cts.andQuery([\n"+
" cts.jsonPropertyWordQuery('instrument', 'trumpet'),\n"+
" cts.jsonPropertyWordQuery('lastName', ['Armstrong', 'Davis'])\n"+
Expand Down Expand Up @@ -1447,7 +1449,7 @@ public void testSampleBy() throws IOException {
PlanSampleByOptions options = p.sampleByOptions().withLimit(2);

PlanBuilder.ExportablePlan builtPlan =
p.fromView("opticUnitTest", "musician")
p.fromView("opticUnitTest", VIEW_NAME)
.sampleBy(options);

RowSet<RowRecord> rows = rowMgr.resultRows(builtPlan);
Expand All @@ -1461,7 +1463,7 @@ public void testSampleByNoArg() throws IOException {
PlanBuilder p = rowMgr.newPlanBuilder();

PlanBuilder.ExportablePlan builtPlan =
p.fromView("opticUnitTest", "musician")
p.fromView("opticUnitTest", VIEW_NAME)
.sampleBy();

RowSet<RowRecord> rows = rowMgr.resultRows(builtPlan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void testDatatypeRoundtrip() throws Exception {
@Test
public void aliasTest() throws IOException {
PlanBuilder.ModifyPlan plan =
p.fromView("opticUnitTest", "musician")
p.fromView("opticUnitTest", "musician_ml10")
.orderBy(p.col("lastName"))
.limit(1);

Expand All @@ -267,7 +267,7 @@ public void aliasTest() throws IOException {

RowRecord row = rowItr.next();

for (String colName: new String[]{"opticUnitTest.musician.lastName", "musician.lastName", "lastName"}) {
for (String colName: new String[]{"opticUnitTest.musician_ml10.lastName", "musician_ml10.lastName", "lastName"}) {
RowRecord.ColumnKind expectedKind = RowRecord.ColumnKind.ATOMIC_VALUE;
RowRecord.ColumnKind actualKind = row.getKind(colName);
assertEquals(expectedKind, actualKind);
Expand Down
Loading

0 comments on commit 5f4f7a8

Please sign in to comment.