Skip to content

Commit b33c545

Browse files
committed
fix json_extract function with stat4
Signed-off-by: Dorin Hogea <dhogea@bloomberg.net>
1 parent da4013c commit b33c545

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

sqlite/src/dttz.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ void register_date_functions(sqlite3 * db) {
8484
}
8585
}
8686

87+
void func_needs_vdbe(sqlite3_context *context, FuncDef *pFunc, Vdbe *pVdbe)
88+
{
89+
if (pFunc->xSFunc == currentTS || pFunc->xSFunc == nowFunc || pFunc->xSFunc == nextSequence)
90+
context->pVdbe = pVdbe;
91+
}
92+
8793
static int _convMem2ClientDatetime(Mem *pMem, void *out, int outlen,
8894
int *outdtsz, int isstring)
8995
{

sqlite/src/vdbeInt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ int convMem2ClientDatetime(Mem *pMem, void *out);
814814
int convMem2ClientDatetimeStr(Mem *pMem, void *out, int outlen, int *outdtsz);
815815
int convDttz2ClientDatetime(const dttz_t *, const char *tzname, void *out, int sqltype);
816816
const char *get_clnt_tz();
817+
void func_needs_vdbe(sqlite3_context *context, FuncDef *pFunc, Vdbe *pVdbe);
817818

818819
int sqliteVdbeMemDecimalBasicArithmetics(Mem *a, Mem *b, int opcode, Mem * res, int flipped);
819820

sqlite/src/vdbemem.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,15 @@ static int valueFromFunction(
17261726
ctx.pOut = pVal;
17271727
ctx.pFunc = pFunc;
17281728
#if defined(SQLITE_BUILDING_FOR_COMDB2)
1729-
ctx.pVdbe = db->pVdbe;
1729+
/* Certain comdb2 functions save info in pVdbe, and we need set the pVdbe
1730+
* pointer in the function context.
1731+
* Example: now() needs the the default precision to work.
1732+
* Sqlite json on the other hand expectgs db pVdbe pointer to be NULL
1733+
* as it is using it to store internal json info.
1734+
* Below function sets pVdbe in the function context only for comdb2
1735+
* variants that requires it.
1736+
*/
1737+
func_needs_vdbe(&ctx, pFunc, db->pVdbe);
17301738
#endif /* defined(SQLITE_BUILDING_FOR_COMDB2) */
17311739
pFunc->xSFunc(&ctx, nVal, apVal);
17321740
if( ctx.isError ){
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(id=123, b1=x'59')

tests/misstable_remsql.test/test_missing.sh

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ a_cdb2config=$4
1313
a_dbdir=$5
1414
a_testdir=$6
1515

16+
#TEST1 checking for missed table followed by good tables
17+
echo "TEST1 checking for missed table followed by good tables"
18+
1619
output=run.out
1720

1821
REM_CDB2_OPTIONS="--cdb2cfg ${a_remcdb2config}"
@@ -51,7 +54,6 @@ cdb2sql ${SRC_CDB2_OPTIONS} --host $mach $a_dbname "select * from LOCAL_${a_remd
5154
cdb2sql ${SRC_CDB2_OPTIONS} --tabs --host $mach $a_dbname "exec procedure sys.cmd.send(\"fdb info db\")" 2>&1 | cut -f 5- -d ' ' >> $output
5255

5356

54-
5557
#convert the table to actual dbname
5658
sed "s/dorintdb/${a_remdbname}/g" output.log > output.log.actual
5759

@@ -74,7 +76,8 @@ if [[ "$testcase_output" != "$expected_output" ]]; then
7476
exit 1
7577
fi
7678

77-
#TEST2 start by accessing a missing table, followed by good tables
79+
#TEST2 following test one, again try to access a missing table, followed by good tables
80+
echo "TEST2 following test one, again try to access a missing table, followed by good tables"
7881

7982
output=run.2.out
8083

@@ -109,6 +112,7 @@ cdb2sql ${SRC_CDB2_OPTIONS} --host $mach $a_dbname "select dbname, tablename, in
109112
sed "s/dorintdb/${a_remdbname}/g" output_2.log > output_2.log.actual
110113

111114
# validate results
115+
112116
testcase_output=$(cat $output)
113117
expected_output=$(cat output_2.log.actual)
114118
if [[ "$testcase_output" != "$expected_output" ]]; then
@@ -127,5 +131,44 @@ if [[ "$testcase_output" != "$expected_output" ]]; then
127131
exit 1
128132
fi
129133

134+
#TEST3 check that json_extract works - patch for function context
135+
echo "TEST3 check that json_extract works - patch for function context"
136+
137+
output=run.3.out
138+
139+
cdb2sql ${REM_CDB2_OPTIONS} $a_remdbname default "analyze t" > $output 2>&1
140+
141+
echo cdb2sql ${SRC_CDB2_OPTIONS} $a_dbname default "select * from LOCAL_${a_remdbname}.t where json_extract( '{\"bb\":123}', '$.bb') = id"
142+
cdb2sql ${SRC_CDB2_OPTIONS} $a_dbname default "select * from LOCAL_${a_remdbname}.t where json_extract( '{\"bb\":123}', '$.bb') = id" > $output 2>&1
143+
cdb2sql ${SRC_CDB2_OPTIONS} $a_dbname default "select * from LOCAL_${a_remdbname}.t where json_extract( '{\"bb\":123}', '$.bb' ) = id"
144+
145+
if (( $? != 0 )) ; then
146+
echo "Failure: select exit code $?"
147+
exit 1
148+
fi
149+
150+
#convert the table to actual dbname
151+
sed "s/dorintdb/${a_remdbname}/g" output_3.log > output_3.log.actual
152+
153+
# validate results
154+
155+
testcase_output=$(cat $output)
156+
expected_output=$(cat output_3.log.actual)
157+
if [[ "$testcase_output" != "$expected_output" ]]; then
158+
159+
# print message
160+
echo " ^^^^^^^^^^^^"
161+
echo "The above testcase (${testcase}) has failed!!!"
162+
echo " "
163+
echo "Use 'diff <expected-output> <my-output>' to see why:"
164+
echo "> diff ${PWD}/{output_2.log.actual,$output}"
165+
echo " "
166+
diff output_3.log.actual $output
167+
echo " "
168+
169+
# quit
170+
exit 1
171+
fi
172+
130173

131174
echo "Testcase passed."

0 commit comments

Comments
 (0)