Skip to content

Commit a7fb879

Browse files
committed
Resolution for #67: Added CLI options --limit and --paginate
1 parent 31e2671 commit a7fb879

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@
476476
<plugin>
477477
<groupId>com.google.cloud.tools</groupId>
478478
<artifactId>jib-maven-plugin</artifactId>
479-
<version>3.2.0</version>
479+
<version>3.4.4</version>
480480
</plugin>
481481
<plugin>
482482
<artifactId>jdeb</artifactId>

rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/cmd/CmdSparqlIntegrateMain.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.concurrent.Callable;
1212

1313
import org.aksw.jenax.arq.picocli.CmdMixinArq;
14+
import org.aksw.jenax.arq.picocli.CmdMixinSparqlPaginate;
1415
import org.aksw.rdf_processing_toolkit.cli.cmd.CmdCommonBase;
1516
import org.aksw.rdf_processing_toolkit.cli.cmd.VersionProviderRdfProcessingToolkit;
1617
import org.aksw.sparql_integrate.cli.main.SparqlIntegrateCmdImpls;
@@ -75,8 +76,6 @@ public class CmdSparqlIntegrateMain
7576
@Option(names = { "--cache-rewrite-groupby" }, description="Cache GROUP BY operations individually. Ignored if no cache engine is specified.") //, defaultValue = "false", fallbackValue = "true")
7677
public boolean cacheRewriteGroupBy = false;
7778

78-
79-
8079
@Option(names = { "--tmpdir" }, description="Temporary directory")
8180
public String tempPath = StandardSystemProperty.JAVA_IO_TMPDIR.value();
8281

@@ -96,6 +95,10 @@ public class CmdSparqlIntegrateMain
9695
@Mixin
9796
public CmdMixinArq arqConfig = new CmdMixinArq();
9897

98+
/** Mixin for result set limit and pagination */
99+
@Mixin
100+
public CmdMixinSparqlPaginate paginationConfig = new CmdMixinSparqlPaginate();
101+
99102
@Option(names= {"--bnp", "--bnode-profile"}, description="Blank node profile, empty string ('') to disable; 'auto' to autodetect, defaults to ${DEFAULT-VALUE}", defaultValue = "")
100103
public String bnodeProfile = null;
101104

rdf-processing-toolkit-cli/src/main/java/org/aksw/sparql_integrate/cli/main/SparqlIntegrateCmdImpls.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,16 @@ public static int sparqlIntegrate(CmdSparqlIntegrateMain cmd) throws Exception {
484484
}
485485
}
486486

487+
Long resultSetPageSize = cmd.paginationConfig.queryPageSize;
488+
if (resultSetPageSize != null && resultSetPageSize > 0) {
489+
dataSourceTmp = RdfDataEngines.wrapWithDataSourceTransform(dataSourceTmp, ds -> RdfDataSources.withPagination(ds, resultSetPageSize));
490+
}
491+
492+
Long queryLimit = cmd.paginationConfig.queryLimit;
493+
if (queryLimit != null && queryLimit > 0) {
494+
dataSourceTmp = RdfDataEngines.wrapWithDataSourceTransform(dataSourceTmp, ds -> RdfDataSources.withLimit(ds, queryLimit));
495+
}
496+
487497
dataSourceTmp = RdfDataEngines.wrapWithQueryTransform(dataSourceTmp, null, QueryExecs::withDetailedHttpMessages);
488498

489499
if (cmd.cachePath != null) {
@@ -582,16 +592,19 @@ public static int sparqlIntegrate(CmdSparqlIntegrateMain cmd) throws Exception {
582592

583593
// Load function macros (run sparql inferences first)
584594
Map<String, UserDefinedFunctionDefinition> udfRegistry = new LinkedHashMap<>();
595+
596+
// XXX There should be a separate registry for default macros to load.
597+
loadMacros(macroProfiles, udfRegistry, "macros/ollama.ttl");
598+
585599
for (String macroSource : cmd.macroSources) {
586-
Model model = RDFDataMgr.loadModel(macroSource);
587-
SparqlStmtMgr.execSparql(model, "udf-inferences.rq");
588-
Map<String, UserDefinedFunctionDefinition> contrib = UserDefinedFunctions.load(model, macroProfiles);
589-
udfRegistry.putAll(contrib);
600+
loadMacros(macroProfiles, udfRegistry, macroSource);
590601
}
591602

592603
if (!cmd.macroSources.isEmpty()) {
593-
logger.info("Loaded functions: {}", udfRegistry.keySet());
594-
logger.info("Loaded {} function definitions from {} macro sources.", udfRegistry.size(), cmd.macroSources.size());
604+
if (logger.isInfoEnabled()) {
605+
logger.info("Loaded functions: {}", udfRegistry.keySet());
606+
logger.info("Loaded {} function definitions from {} macro sources.", udfRegistry.size(), cmd.macroSources.size());
607+
}
595608
// ExprTransform eform = new ExprTransformExpand(udfRegistry);
596609
ExprTransform eform = new ExprTransformCopy() {
597610
@Override
@@ -602,8 +615,6 @@ public Expr transform(ExprFunctionN func, ExprList args) {
602615
};
603616
SparqlStmtTransform stmtTransform = SparqlStmtTransforms.ofExprTransform(eform);
604617
dataSourceTmp = RdfDataEngines.wrapWithStmtTransform(dataSourceTmp, stmtTransform);
605-
// QueryTransform qform = q -> QueryUtils.rewrite(q, op -> Transformer.transform(null, eform, op));
606-
// dataSourceTmp = RdfDataEngines.wrapWithQueryTransform(dataSourceTmp, qform, null);
607618
}
608619

609620
RdfDataEngine datasetAndDelete = dataSourceTmp;
@@ -848,10 +859,14 @@ public void afterExec() {
848859

849860
server.start();
850861

862+
// Try to get the host address from a network device (e.g. within a docker container)
851863
String hostAddress;
852864
try(final DatagramSocket socket = new DatagramSocket()){
853865
socket.connect(InetAddress.getByName("1.1.1.1"), 53);
854866
hostAddress = socket.getLocalAddress().getHostAddress();
867+
} catch (Exception e) {
868+
// Fall back to localhost
869+
hostAddress = "localhost";
855870
}
856871
URI browseUri = new URI("http://"+hostAddress+":" + port + "/");
857872
if (Desktop.isDesktopSupported()) {
@@ -928,6 +943,14 @@ public void afterExec() {
928943
return exitCode;
929944
}
930945

946+
private static void loadMacros(Set<String> macroProfiles, Map<String, UserDefinedFunctionDefinition> udfRegistry,
947+
String macroSource) {
948+
Model model = RDFDataMgr.loadModel(macroSource);
949+
SparqlStmtMgr.execSparql(model, "udf-inferences.rq");
950+
Map<String, UserDefinedFunctionDefinition> contrib = UserDefinedFunctions.load(model, macroProfiles);
951+
udfRegistry.putAll(contrib);
952+
}
953+
931954
/** Be careful not to call within a read transaction! */
932955
public static void updateSpatialIndex(Dataset dataset) {
933956
Context cxt = dataset.getContext();

0 commit comments

Comments
 (0)