Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.

Bug 1105101

Summary: MongoDB: Function substring - starting index and number of arguments
Product: [JBoss] JBoss Data Virtualization 6 Reporter: Filip Elias <felias>
Component: TeiidAssignee: Van Halbert <vhalbert>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 6.0.0CC: atangrin, dlesage, vhalbert
Target Milestone: ER5Keywords: QA-Closed
Target Release: 6.1.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
There were two minor bugs in MongoDB's function substring(). The code has now been fixed so that users will no longer encounter them.
Story Points: ---
Clone Of: Environment:
DV 6.0 + rollup
Last Closed: 2016-02-10 08:48:52 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Filip Elias 2014-06-05 11:47:55 UTC
Two minor bugs in function substring()

Mongo's function $substr takes only 3 arguments so this query fails:

SELECT intkey, SUBSTRING(BQT1.SmallA.stringkey, 1) FROM BQT1.SmallA ORDER BY intkey

Exception:13:18:48,220 ERROR [org.teiid.CONNECTOR] (Worker38_QueryProcessorQueue345) Connector worker process failed for atomic-request=omsmHP0o16Sa.40.0.86: com.mongodb.CommandFailureException: { "serverUsed" : "localhost/127.0.0.1:27017" , "errmsg" : "exception: the $substr operator requires 3 operand(s)" , "code" : 16020 , "ok" : 0.0}
	at com.mongodb.CommandResult.getException(CommandResult.java:71)
	at com.mongodb.CommandResult.throwOnError(CommandResult.java:110)
	at com.mongodb.DBCollection.aggregate(DBCollection.java:1308)

Generated mongo command: 
{ aggregate: "smalla", pipeline: [ { $project: { c_0: "$INTKEY", c_1: { $substr: [ "$STRINGKEY", 1 ] } } }, { $sort: { c_0: 1 } } ] }


Mongo's $substr function second argument represents number of bytes to skip, not the starting index. The function substring(StringKey,1,1) returns the second letter, but it should return the first letter.

Comment 1 JBoss JIRA Server 2014-06-05 20:14:13 UTC
Ramesh Reddy <rareddy> updated the status of jira TEIID-2988 to Resolved

Comment 2 Filip Elias 2014-11-24 12:52:48 UTC
The second problem with SUBSTRING's argument is not fixed. Arguments/indexes in teiid substring function are 1-based while arguments in mongo $substr function are 0-based. Translator should compensate it.

How to reproduce:

SELECT SUBSTRING(BQT1.SmallA.stringkey, 1) FROM BQT1.SmallA ORDER BY intkey

Expected result: SUBSTRING function returns the whole stringkey value

Actual result: SUBSTRING function returns stringkey value without the first letter

Comment 3 JBoss JIRA Server 2014-11-24 13:29:52 UTC
Van Halbert <vhalbert> updated the status of jira TEIID-2988 to Reopened

Comment 4 JBoss JIRA Server 2014-11-25 18:20:30 UTC
Ramesh Reddy <rareddy> updated the status of jira TEIID-2988 to Resolved

Comment 5 JBoss JIRA Server 2015-07-06 19:58:12 UTC
Steven Hawkins <shawkins> updated the status of jira TEIID-2988 to Closed