Skip to content
Permalink
Browse files

allow attribute names starting with numbers in select list

  • Loading branch information...
glookka committed May 6, 2019
1 parent 2fb0297 commit 849c16e1040f382795ba0635cb48686f9db4f2d8
Showing with 58 additions and 3 deletions.
  1. +18 −1 src/sphinxexpr.cpp
  2. +1 −1 src/sphinxql.l
  3. +1 −1 test/test_125/model.bin
  4. +38 −0 test/test_125/test.xml
@@ -3505,19 +3505,36 @@ int ExprParser_t::GetToken ( YYSTYPE * lvalp )
if ( isdigit ( m_pCur[0] ) )
return ParseNumeric ( lvalp, &m_pCur );

bool bBackQuote = m_pCur[0]=='`';

// check for field, function, or magic name
if ( sphIsAttr ( m_pCur[0] )
|| ( m_pCur[0]=='@' && sphIsAttr ( m_pCur[1] ) && !isdigit ( m_pCur[1] ) ) )
|| ( m_pCur[0]=='@' && sphIsAttr ( m_pCur[1] ) && !isdigit ( m_pCur[1] ) )
|| ( bBackQuote && sphIsAttr ( m_pCur[1] ) ) )
{
// get token
const char * pStart = m_pCur++;
if ( bBackQuote )
pStart++;

while ( sphIsAttr ( *m_pCur ) ) m_pCur++;

CSphString sTok;
sTok.SetBinary ( pStart, m_pCur-pStart );
CSphString sTokMixedCase = sTok;
sTok.ToLower ();

if ( bBackQuote )
{
if ( *m_pCur!='`' )
{
m_sLexerError.SetSprintf ( "expected '`' near '%s'", m_pCur );
return -1;
}

m_pCur++;
}

// check for magic name
if ( sTok=="@id" )
sTok = "id";
@@ -192,7 +192,7 @@ ALPHA [a-zA-Z_]+
@@{ID} { YYSTOREBOUNDS; return TOK_SYSVAR; }
@@{ID}\.{ID} { YYSTOREBOUNDS; return TOK_SYSVAR; }
`{ID}` { YYSTOREBOUNDS; lvalp->m_iStart++; lvalp->m_iEnd--; return TOK_IDENT; }
`{DIGIT}+{ID}` { YYSTOREBOUNDS; lvalp->m_iStart++; lvalp->m_iEnd--; return TOK_IDENT; } // allow `123xyz` column names
`{DIGIT}+{ID}` { YYSTOREBOUNDS; return TOK_IDENT; } // allow `123xyz` column names
{ID}:{ID} { YYSTOREBOUNDS; return TOK_IDENT; }

{SPACE}+ { ; }

Large diffs are not rendered by default.

@@ -135,6 +135,20 @@ index test_json
path = <data_path/>/test_json
}

source test_name
{
type = mysql
<sql_settings/>
sql_query = select * from name_table
sql_attr_uint = 123_attr1
sql_attr_uint = 10000attr2
}

index test_name
{
source = test_name
path = <data_path/>/test_name
}
</config>

<db_create>
@@ -186,12 +200,21 @@ CREATE TABLE json_table (
PRIMARY KEY (`id`)
);
</db_create>
<db_create>
CREATE TABLE name_table (
`id` int(11),
`title` varchar(255),
`123_attr1` int(11),
`10000attr2` int(11)
);
</db_create>

<db_drop>DROP TABLE IF EXISTS test_table;</db_drop>
<db_drop>DROP TABLE IF EXISTS cmp_table;</db_drop>
<db_drop>DROP TABLE IF EXISTS string_table;</db_drop>
<db_drop>DROP TABLE IF EXISTS string_table1;</db_drop>
<db_drop>DROP TABLE IF EXISTS json_table;</db_drop>
<db_drop>DROP TABLE IF EXISTS name_table;</db_drop>

<db_insert>
INSERT INTO test_table ( id, aa, title, mm, kk, f1, f2 ) VALUES
@@ -232,6 +255,12 @@ INSERT INTO json_table VALUES
(3,2,'another doc','{"name":"Charlie","uid":345, "lon":-0.0721455, "lat":0.926761, "pct":4.1, "sq":225, "poly":"-1,2,12,4,5,6", "points":[-1,2,12,4,5,6]}')
</db_insert>

<db_insert>
INSERT INTO name_table VALUES
(1,'test one',100,1000),
(2,'test two',200,2000)
</db_insert>

<query_attributes>
<attr>aa</attr>
<attr>sel</attr>
@@ -458,6 +487,15 @@ INSERT INTO json_table VALUES
<sphinxql>SELECT CONTAINS(POLY2D(j.points[0], j.points[1], j.points[2], j.points[3], j.points[4], j.points[5]), 2, 3) FROM test_json</sphinxql>
<sphinxql>SELECT CONTAINS(POLY2D(j.poly), j.pct, 3 ) FROM test_json</sphinxql>
<sphinxql>SELECT CONTAINS(POLY2D(j.poly), 3, j.pct ) FROM test_json</sphinxql>

<!-- regression for attribute names starting w/numbers -->
<sphinxql>SELECT 123_attr1 FROM test_name</sphinxql>
<sphinxql>SELECT `123_attr1` FROM test_name</sphinxql>
<sphinxql>SELECT `123_attr1` 000alias FROM test_name</sphinxql>
<sphinxql>SELECT `123_attr1` `000alias` FROM test_name</sphinxql>
<sphinxql>SELECT `123_attr1` `000alias` FROM test_name WHERE `000alias`>100 </sphinxql>
<sphinxql>SELECT `123_attr1` `000alias1`, `10000attr2` `000alias2` FROM test_name WHERE `000alias1`>100 AND `000alias2`=2000 </sphinxql>

</sphqueries>

</test>

0 comments on commit 849c16e

Please sign in to comment.
You can’t perform that action at this time.