Search code examples
databasecassandratimestampwso2wso2-data-services-server

WSO2 DSS issue when selecting Timestamps from Database


I've an issue defining a query to get some data out of Cassandra in WSO2 DSS. The query (and the operation) itself is working but my problem is when I try to get a timestamp as a result. I only get the date and the timezone (2017-01-11+0100) the time part is missing. I guess that this is somehow related on the mapping to dateTime xsdType that is not working correctly. Did you already face this issue, and do you have a solution to get the timestamp?

Here is a query sample

<query id="getDataQuery" useConfig="CassandraDB">
    <expression>SELECT ts,value FROM keyspace.ts_tp WHERE name = :name</expression>
    <result element="result" rowName="data">
        <element column="ts" name="ts" xsdType="dateTime"/>
        <element column="value" name="value" xsdType="decimal"/>
    </result>
    <param name="name" paramType="SCALAR" sqlType="STRING"/>
</query>

Thanks


Solution

  • Seems to be an issue in dss dateTime mapping, I opened a Jira ticket @wso2 to be sure. In order to make my call return the right values I made the following (Warning painful solution :))

    The query returns now the unix Timestamp in ms

    <query id="getDataQuery" useConfig="CassandraDB">
        <expression>SELECT unixTimestampOf(minTimeuuid(ts)) as dt,value FROM keyspace.ts_tp WHERE source = :source and name = :name and bucket = :bucket and ts &gt;= :tsFrom and ts &lt;= :tsTo</expression>
        <result element="result" rowName="data">
            <element column="dt" name="ts" xsdType="int"/>
            <element column="value" name="value" xsdType="decimal"/>
        </result>
        <param name="source" paramType="SCALAR" sqlType="STRING"/>
        <param name="name" paramType="SCALAR" sqlType="STRING"/>
        <param name="bucket" paramType="SCALAR" sqlType="INTEGER"/>
        <param name="tsFrom" paramType="SCALAR" sqlType="TIMESTAMP"/>
        <param name="tsTo" paramType="SCALAR" sqlType="TIMESTAMP"/>
    </query>
    

    Once I get the result I apply an XSL transformation to compute the dates

    <xsl:stylesheet exclude-result-prefixes="xsl soapenv" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output encoding="utf-8" indent="yes" method="xml" omit-xml-declaration="yes"/>
       <xsl:template match="@*|node()">
          <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
          </xsl:copy>
       </xsl:template>
    
        <xsl:template match="dt">
          <xsl:element name="ts">
             <xsl:value-of select='xs:dateTime("1970-01-01T00:00:00") + . * xs:dayTimeDuration("PT0.001S")'/>
          </xsl:element>
        </xsl:template>
    </xsl:stylesheet>
    

    It needs to be tested with different time zones, and day light savings but it seems to be a working hack, waiting for the official fix.