Skip to content

Commit a5b25c1

Browse files
committed
Postfixes for #8418: new UNLIST function, by Alexey Chudaykin. Cleanup the unused parser rules. Fix result for multi-byte input. Add BLR filter for the new verb. Preserve the original charset of the input string/blob even if it's NONE.
1 parent fc63651 commit a5b25c1

File tree

5 files changed

+68
-28
lines changed

5 files changed

+68
-28
lines changed

src/dsql/parse.y

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6642,26 +6642,6 @@ table_value_function_correlation_name
66426642
: as_noise symbol_table_alias_name { $$ = $2; }
66436643
;
66446644

6645-
%type <metaNameArray> table_value_function_columns
6646-
table_value_function_columns
6647-
: table_value_function_column
6648-
{
6649-
ObjectsArray<MetaName>* node = newNode<ObjectsArray<MetaName>>();
6650-
node->add(*$1);
6651-
$$ = node;
6652-
}
6653-
| table_value_function_columns ',' table_value_function_column
6654-
{
6655-
ObjectsArray<MetaName>* node = $1;
6656-
node->add(*$3);
6657-
$$ = node;
6658-
}
6659-
;
6660-
6661-
%type <metaNamePtr> table_value_function_column
6662-
table_value_function_column
6663-
: symbol_column_name { $$ = $1; }
6664-
;
66656645

66666646
// other clauses in the select expression
66676647

src/jrd/RecordSourceNodes.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "../dsql/metd_proto.h"
3838
#include "../dsql/pass1_proto.h"
3939
#include "../jrd/optimizer/Optimizer.h"
40+
#include "../dsql/DSqlDataTypeUtil.h"
4041

4142
using namespace Firebird;
4243
using namespace Jrd;
@@ -4247,27 +4248,26 @@ dsql_fld* UnlistFunctionSourceNode::makeField(DsqlCompilerScratch* dsqlScratch)
42474248
if (inputList)
42484249
inputList = Node::doDsqlPass(dsqlScratch, inputList, false);
42494250

4250-
dsc desc;
4251-
4252-
auto inputItem = inputList->items.begin()->getObject();
4251+
const auto inputItem = inputList->items.begin()->getObject();
42534252
inputItem->setParameterType(
42544253
dsqlScratch, [](dsc* desc) { desc->makeVarying(1024, CS_dynamic); }, false);
42554254

42564255
dsql_fld* field = dsqlField;
42574256

42584257
if (!field)
42594258
{
4260-
auto newField = FB_NEW_POOL(dsqlScratch->getPool()) dsql_fld(dsqlScratch->getPool());
4259+
const auto newField = FB_NEW_POOL(dsqlScratch->getPool()) dsql_fld(dsqlScratch->getPool());
42614260
field = newField;
42624261

4262+
dsc desc;
42634263
DsqlDescMaker::fromNode(dsqlScratch, &desc, inputItem);
4264-
42654264
USHORT ttype = desc.getCharSet();
42664265

4267-
if (ttype == CS_NONE)
4266+
if (ttype == CS_NONE && !desc.isText() && !desc.isBlob())
42684267
ttype = CS_ASCII;
42694268

4270-
desc.makeText(32, ttype);
4269+
const auto bytesPerChar = DSqlDataTypeUtil(dsqlScratch).maxBytesPerChar(ttype);
4270+
desc.makeText(bytesPerChar * DEFAULT_UNLIST_TEXT_LENGTH, ttype);
42714271
MAKE_field(newField, &desc);
42724272
newField->fld_id = 0;
42734273
}

src/jrd/RecordSourceNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ class UnlistFunctionSourceNode : public TableValueFunctionSourceNode
10331033
dsql_fld* makeField(DsqlCompilerScratch* dsqlScratch) final;
10341034

10351035
static constexpr char const* FUNC_NAME = "UNLIST";
1036+
static constexpr USHORT DEFAULT_UNLIST_TEXT_LENGTH = 32;
10361037
};
10371038

10381039
} // namespace Jrd

src/jrd/blp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,6 @@ static const struct
261261
{"select_procedure", invsel_procedure},
262262
{"default_arg", zero},
263263
{"cast_format", cast_format},
264+
{"table_value_fun", table_value_fun},
264265
{0, 0}
265266
};

src/yvalve/gds.cpp

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ const int op_dcl_local_table = 31;
325325
const int op_outer_map = 32;
326326
const int op_invoke_function = 33;
327327
const int op_invsel_procedure = 34;
328+
const int op_table_value_fun = 35;
328329

329330
static const UCHAR
330331
// generic print formats
@@ -419,7 +420,8 @@ static const UCHAR
419420
in_list[] = { op_line, op_verb, op_indent, op_word, op_line, op_args, 0},
420421
invoke_function[] = { op_invoke_function, 0 },
421422
invsel_procedure[] = { op_invsel_procedure, 0 },
422-
cast_format[] = { op_line, op_indent, op_byte, op_literal, op_line, op_indent, op_dtype, op_line, op_verb, 0 };
423+
cast_format[] = { op_line, op_indent, op_byte, op_literal, op_line, op_indent, op_dtype, op_line, op_verb, 0 },
424+
table_value_fun[] = { op_table_value_fun, 0 };
423425

424426

425427
#include "../jrd/blp.h"
@@ -4173,6 +4175,62 @@ static void blr_print_verb(gds_ctl* control, SSHORT level)
41734175
break;
41744176
}
41754177

4178+
case op_table_value_fun:
4179+
{
4180+
offset = blr_print_line(control, static_cast<SSHORT>(offset));
4181+
4182+
static const char* subCodes[] =
4183+
{
4184+
nullptr,
4185+
"unlist",
4186+
};
4187+
4188+
blr_indent(control, level);
4189+
4190+
blr_operator = control->ctl_blr_reader.getByte();
4191+
4192+
if (blr_operator == 0 || blr_operator >= FB_NELEM(subCodes))
4193+
blr_error(control, "*** invalid blr_table_value_fun sub code ***");
4194+
4195+
blr_format(control, "blr_table_value_fun_%s, ", subCodes[blr_operator]);
4196+
4197+
switch (blr_operator)
4198+
{
4199+
case blr_table_value_fun_unlist:
4200+
4201+
blr_print_byte(control);
4202+
4203+
blr_print_name(control);
4204+
4205+
n = blr_print_word(control);
4206+
offset = blr_print_line(control, static_cast<SSHORT>(offset));
4207+
4208+
++level;
4209+
while (n-- > 0)
4210+
blr_print_verb(control, level);
4211+
4212+
blr_indent(control, level);
4213+
n = blr_print_word(control);
4214+
4215+
while (n-- > 0)
4216+
{
4217+
offset = blr_print_line(control, static_cast<SSHORT>(offset));
4218+
blr_indent(control, level);
4219+
blr_print_dtype(control);
4220+
blr_print_name(control);
4221+
}
4222+
--level;
4223+
4224+
offset = blr_print_line(control, static_cast<SSHORT>(offset));
4225+
break;
4226+
4227+
default:
4228+
fb_assert(false);
4229+
}
4230+
4231+
break;
4232+
}
4233+
41764234
default:
41774235
fb_assert(false);
41784236
break;

0 commit comments

Comments
 (0)