openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.71k forks source link

[influxdb] Queries with item state as filter criteria throws runtime exceptions #5888

Closed philippwaller closed 3 years ago

philippwaller commented 4 years ago

I noticed the following issue: If I create a FilterCriteria object and set setState to a proper value, the query against influxDB end up with an error message.

javax.script.ScriptException: java.lang.RuntimeException: {"error":"error parsing query: found EQ, expected ; at line 1, char 76"}

Please find attached a JSR223 script as a testcase, written in groovy:

import org.eclipse.smarthome.core.library.types.OpenClosedType
import org.eclipse.smarthome.core.persistence.FilterCriteria
import org.eclipse.smarthome.core.persistence.PersistenceService
import org.eclipse.smarthome.core.persistence.PersistenceServiceRegistry
import org.eclipse.smarthome.core.persistence.QueryablePersistenceService
import org.osgi.framework.BundleContext
import org.osgi.framework.FrameworkUtil
import org.osgi.framework.ServiceReference
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Logger log = LoggerFactory.getLogger("influxDB.issue")

// load PersistenceServiceRegistry
BundleContext context = FrameworkUtil.getBundle(se.class).getBundleContext()
ServiceReference<PersistenceServiceRegistry>[] refs = context.getAllServiceReferences(
        'org.eclipse.smarthome.core.persistence.PersistenceServiceRegistry',
        '(component.name=org.eclipse.smarthome.core.persistence.internal.PersistenceServiceRegistryImpl)'
)
PersistenceServiceRegistry persistenceRegistry = context.getService(refs[0]) as PersistenceServiceRegistry

// assumes that influxDB is your default persistence layer
PersistenceService service = persistenceRegistry.getDefault()
QueryablePersistenceService qService = (QueryablePersistenceService) service
FilterCriteria filter = new FilterCriteria()
        .setItemName('EW_DoorSensorApartmentDoor_State')
        .setPageSize(10)
        // here comes the troublemaker
        .setState(OpenClosedType.OPEN)

// results in RuntimeException: {"error":"error parsing query: found EQ, expected ; at line 1, char 76"}
log.warn('Query Result: {}', qService.query(filter).dump())

I guess there is an issue during the query creation. How can I log the influxDB communication ?