How to do a count(*) with Jena Adapter?

Hi, I am trying to do a count(*). I know it's not part of the SPARQL 1.0 standard, but it is supported in ARQ, and presumably by the Jena Adapter too then?
Other examples I have been able to find do an iteration over the resultset to get a count, but that is not acceptable since I have millions of triples. In my tests it took 15 seconds to return the count by using iteration. Oracle Semantic is advertised as scaling to "hundreds of millions of triples"; so how do I do a simple count(*) aggregation?
Below is the code I tried. It works with a regular jena default model, returning the expected result of "2", but the result is empty if I use the Oracle Jena adapter.
import oracle.spatial.rdf.client.jena.ModelOracleSem;
import oracle.spatial.rdf.client.jena.Oracle;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Model;
public class OracleJenaAdapterCountTest {
     public static void main(String[] args) throws Exception {
          String szJdbcURL = "jdbc:oracle:thin:@dragon12:1521:mydb";
          String szUser = "mydb";
          String szPasswd = "yeahright";
          String szModelName = "kp_mydb_model";
          Oracle oracle = new Oracle(szJdbcURL, szUser, szPasswd);
          Model model = ModelOracleSem.createOracleSemModel(oracle,
          szModelName);
          // this one works
          //Model model = ModelFactory.createDefaultModel();
          model.getGraph().add(
                    Triple.create(Node.createURI("http://example.com/John"),
                              Node.createURI("http://example.com/fatherOf"),
                              Node.createURI("http://example.com/Mary")));
          model.getGraph().add(
                    Triple.create(Node.createURI("http://example.com/John"),
                              Node.createURI("http://example.com/fatherOf"),
                              Node.createURI("http://example.com/Bob")));
          Query query = QueryFactory
                    .create("select (count(*) as ?count) {?f <http://example.com/fatherOf> ?k .}");
          QueryExecution qexec = QueryExecutionFactory.create(query, model);
          ResultSet results = qexec.execSelect();
          ResultSetFormatter.out(System.out, results, query);
          model.close();
          oracle.dispose();
}

Hi,
Which version of Jena/Jena Adapter are you using?
I am a bit surprised that your query did not throw out an exception. I need to set Syntax.syntaxARQ
in the query creation, as follows. (Without it, I got com.hp.hpl.jena.query.QueryParseException when
executing the same code.)
Query query = QueryFactory
.create("select (count(*) as ?count) {?f <http://example.com/fatherOf> ?k .}",
Syntax.syntaxARQ);
Once I have the above change, I did get the right count.
| count |
=========
| 2 |
The above query is not the most efficient one in terms of getting the count. Because we have to select out all projection and send the data from the database to the Java client. If you are using the latest Jena Adapter, you can use the count_only which will instruct the underlying query to return the count directly from the database.
Query query = QueryFactory
.create("PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#count_only> select ?count {?f <http://example.com/fatherOf> ?k .}",
Syntax.syntaxARQ);
Cheers,
Zhe Wu

Similar Messages

  • How to trigger a counter with AI input

    Hi,I have a question on how to trigger a counter with AI input.We are using a DAQ board with two counters(counter 0 & 1),and we have an external synchronization signal input at a frequency of 50 Hz or so.The counter is set to event counting mode.Now we want to trigger one of the counters so that the counter starts a new counting process each time it detects a rising/falling edge from the sync signal.Can anybody kindly show me how to achieve this?Thanks a lot.
    Regards
    Verdi

    Verdi,
    I think that the behavior you are looking for can be achieved by configuring the counter for buffered period measurement. The counter starts counting from some initial value with each rising or falling edge on the gate. You could also use buffered event counting, but the count value will not reset with each edge on the gate. I don't know what you're using to program the board, but you could start by looking at the counter examples that are installed with NI-DAQ.
    Hope this helps,
    Erin

  • How do I configure logging for Jena Adapter?

    The software I'm developing uses the jdk logger, and sends the output to a log file. I'd like to send log messages from the Jena adapter to the same location. Also, what are the names of the logged components, and how can you adjust the log levels?

    Those are internal logs. Behind the scene, Jena Adaptor is using apache commons logging.
    To disable those verbose logging output, you can set the following JVM properties.
    -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
    -Dorg.apache.commons.logging.simplelog.defaultlog=warn
    Thanks,
    Zhe Wu

  • How to create a counter (with fixed increment) in DME file

    Hi Experts,
    Is there a way to define a counter in one of the Segment/loop of DME (Such as number of invoices), where we have to increment the actual value of the counter reading by a fixed value, say 2. Example, if the counter can print the invoice numbers as 1,2,3, 4,5 etc. then it should rather print X+2 in each case, i.e. 3, 4, 5, 6, 7 and so on.
    Regards
    Harsh

    Hi Amitash,
    Thanks for the response. Sorry I couldn't articulate my question correctly. Let me try to rephrase.
    I have to print all the invoice details related to each payment document, in the DME output. One of the field in the invoice details is a simple counter, which prints a simple sequence number 1 to 5 (for 5 invoices). This counter can go upto any number depending on the number of invoices (1 to n). Now with the help of aggregation functions I am able to generate such a counter. But here is the twist now. Instead of printing 1 to 5, the counter should print 3 to 8. ( i.e. 1 to n, it should be printing 3 to n+2 ). Is that possible?
    Regards
    Harsh

  • Message Level Security with SOAP Adapter

    Hi,
    I need to use Message Level Security with my SOAP Adapter. Please let me know if anyone has done the same in the past?
    What are the steps I would need to do? How can I use WSS based security in the SOAP Adapter?

    Hi,
    Message-level security is recommended and sometimes a prerequisite for inter-enterprise communication.
    It improves communication-level security by adding security features that are particularly important for inter-enterprise
    Message-level encryption is required if message content needs to be confidential not only on the communication lines but also in intermediate message stores.
    Refer
    How to use Client Authentication with SOAP Adapter
    XML Encryption Using Web Services Security in SAP NetWeaver XI
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f0650f56-7587-2910-7c99-e1b6ffbe4d50
    http://help.sap.com/saphelp_nw04/helpdata/en/a8/882a40ce93185de10000000a1550b0/frameset.htm
    Thanks
    swarup

  • Jena Adapter and SPARQL web service endpoint

    As I understand, with Jena adapter java interface, the client can connect to Oracle RDF database directly. Why does it still need SPARQL web service endpoint? Does the query request from Jena adapter at client side have to go through SPARQL webservice first then route to Oracle server? Or the query with SPARQL need to go through webservice and non SPARQL query directly go to Oracle server?
    Thanks.

    Hi,
    You are right that a client can connect to Oracle RDF directly through the Jena Adapter. The reason for providing a SPARQL web service endpoint is to give additional interoperability and flexibility. With the SPARQL web service endpoint, one does not even need to write any Java code to interact with the underlying database. It also makes SPARQL federation a lot easier.
    Hope it helps,
    Zhe Wu

  • How do i connect my macbook pro to my tv with my HDMI cord with the adapter to a 32" panasonic vieja tv, how do i connect my macbook pro to my tv with my HDMI cord with the adapter to a 32" panasonic vieja tv?

    how do i connect my macbook pro to my tv with my HDMI cord with the adapter to a 32" panasonic vieja tv?

    get a minidisplayport to HDMI adapter found at http://store.apple.com/us?afid=p219%7CGOUS&cid=AOS-US-KWG
    get a minidisplayport to HDMI adapter found at http://store.apple.com/us?afid=p219%7CGOUS&cid=AOS-US-KWG
    get a minidisplayport to HDMI adapter found at http://store.apple.com/us?afid=p219%7CGOUS&cid=AOS-US-KWG

  • How can I implement a Digital I/O counter with a maximum source frequency of 80 MHz (like 6602 board) using CompactRIO?

    How can I implement a Digital I/O counter with a maximum source frequency of 80 MHz (like 6602 board) using CompactRIO? It appears as if the Digital I/O modules for CompactRIO are much slower than this.
    Thank you,
    --Ray

    Hi Ray,
    The highest frequency input we offer for C Series modules is 20 MHz if you are doing LVTTL and 10 MHz for 5 V TTL.  These modules are the 9402 and 9401, respectively.  Unfortunately, there is no 80 MHz input on this form-factor.
    Regards,
    Chris E.
    Applications Engineer
    National Instruments
    http://www.ni.com/support

  • How to Use SQL Query having IN Clause With DB Adapter

    Hi,
    I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
    Thanks

    invoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter

  • How to use Count with Date Parameters

    Hello,
    I am having issues using the Count() function in conjunction with date parameters.
    This is a Siebel report and in my report I have 2 date parameters(From Date, To Date). In a nutshell I am basically trying to count Opportunities that has a start date within the given date period. However I don't see a reasonable way to put my date parameters within the Count() function. The reason being is that I need to have a huge chunk of code to convert the dates into a common format that can be compared, and it won't even fit within the code block in my rtf template. I am not even sure how to put multiple conditional statements inside a Count() function since all the examples I have seen are very simple.
    Anyone have a suggestion on how to use Count() with date parameters?
    Thanks.

    Any chance you can get the date formats in the correct format from siebel?
    I don't know Siebel - so I can't help you with that. If you get the correct format it is just
    <?count(row[(FromDate>=date) and  (date<=ToDate))?>
    Otherwise the approach would probably need to use string function to get year/monthd/day from the date
    and store it into a varialbe and compare later the same way
    <?variable@incontext:from; ....?>
    <?variable@incontext:to; ...?>
    <?count(row[($from>=date) and  (date<=$to))?>
    Potentially you can use the date functions such as xdofx:to_date to do the conversion
    [http://download.oracle.com/docs/cd/E12844_01/doc/bip.1013/e12187/T421739T481158.htm]
    But I am not sure if they are available in your siebel implementation.
    Hope that helps

  • How to use 45W MagSafe 2 Power Adapter with cable management MagSafe 2 power port macbook air 2013

    How to use 45W MagSafe 2 Power Adapter with cable management MagSafe 2 power port macbook air 2013 there's two plugs do I use both for the safety to work or I just one ? Thanks sorry new macbook air 2013 was given to my daughter fir her 18th bday 2 days ago by my brother

    No, the one is just an extension cord,          just use the 45W charger with its attached thin cord and connect the magnetic magsafe to to the connector on the back left of the macbook Air for use and charging it

  • How can I do Count the Words in a cell with Numbers?

    I'm producing a documentary, with a long list of captions. I was hoping using numbers to organize the captions in sequence. them take the word count and do a simple calculation to work out the numbers of frames required per caption, based on a certian numbers of words per minute.
    I can handle calculations, but can't figure out how/if numbers can count the whole words in a cell and pass that on to a formula.
    I count them manually, but the nature of the script means the captions are being constantly updated.
    Any help appreciated!

    Clever. The only additional suggestion is to use the function Trim() just in case there are extra spaces between the words.
    =LEN(TRIM(B))-LEN(SUBSTITUTE(B," ",""))+1
    Rob

  • How to install a single 2Gb FC adapter with Solaris 10 SPARC ?.

    Hi All,
    I have the Sun Box runing Solaris 10 SPARC, i tried to install PCI single 2Gb FC adapter on this Server in order to connect to Sun Storage FC. At Ok prompt, i tried to run show-devs and looked the path /pci@1e,600000/SUNW,qlc@2 and supposed that physical installation for this adapter is ok.
    But i don't know whether Solaris 10 SPARC included the required drivers for this adapter already or not. Pls show me how to get correct drivers for this adapter and how to test to look if it's working properly under Solaris 10 SPARC ?.
    Thanks
    Scott

    Yes, it's part#X6767A supported for entry SPARC Sun Fire server Line.
    I tried to seach drivers via qlogic.com and it leads me to the sunsolve.com for the download but the download is required to login with a service plan from Sun. So sun wanted to charge for these patches/drivers.
    Do you know which site/link is free for Sun drivers in gerneral ?.
    Thanks
    Scott

  • How to use Count with other all fields

    Hello guys. Sorry about my question because it s syntax but i didnt find in google.
    How can i use count combined with other all fields.
    Like SELECT count(*) 'other all fields like * '  FROM VBAK .
    Thank you very much.

    Don't sure to understand your requirement (count would always be 1, aggregates are only defined with grouping)
    So either use two SELECT (or replace count(*) counting Nr of records selected) if no relation between count and field values....
    Or use a dynamic SELECT syntax. Use FM DDIF_FIELDINFO_GET to  get field list, then create fieldlist with every field name and count(*), create grouplist with every field name
    SELECT (fieldlist)
           INTO ...
           FROM table
           GROUP BY (grouplist).
    Regards,
    Ramond

  • How to do FCC with SFTP adapter (BIC MD tool)

    Dear All,
    Hi guys...can anyone tell how to do FCC with SFTP adapter (Seeburger).
    Can BIC MD tool do the FCC required. can anyone provide link which tells steps to perform FCC with BIC MD.
    we know that we can use the standard module for it. but we are trying to explore this BIC MD and its limitations.
    Regards,
    Senthilprakash

    Hi,
    Im closing this thread as its open for long time now.
    well i have even found the solution for the same.
    SFTP adapter as such does not have FCC functionality.
    we have to use SAP Modules for performing FCC in SFTP adapter.
    for complex conversions (more than 3 levels) we can use BIC tool and then deploy the module in our adapter.
    Regards,
    Senthilprakash.

Maybe you are looking for