You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2014/09/09 14:21:28 UTC
svn commit: r1623782 - in /db/derby/code/trunk/java:
optional/org/apache/derby/optional/lucene/
testing/org/apache/derbyTesting/functionTests/tests/lang/
Author: rhillegas
Date: Tue Sep 9 12:21:27 2014
New Revision: 1623782
URL: http://svn.apache.org/r1623782
Log:
DERBY-6730: Allow case-sensitive names for key columns when creating Lucene indexes; commit derby-6730-01-aa-correctCasing.diff.
Modified:
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java?rev=1623782&r1=1623781&r2=1623782&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java Tue Sep 9 12:21:27 2014
@@ -205,7 +205,8 @@ class LuceneListIndexesVTI extends Strin
{
try {
readSchemaTableColumn();
- StorageFile indexPropertiesFile = LuceneSupport.getIndexPropertiesFile( connection, schema, table, column );
+ String delimitedColumnName = LuceneSupport.delimitID( column );
+ StorageFile indexPropertiesFile = LuceneSupport.getIndexPropertiesFile( connection, schema, table, delimitedColumnName );
rowProperties = readIndexProperties( indexPropertiesFile );
}
catch (IOException ioe) { throw LuceneSupport.wrap( ioe ); }
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java?rev=1623782&r1=1623781&r2=1623782&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java Tue Sep 9 12:21:27 2014
@@ -456,8 +456,9 @@ class LuceneQueryVTI extends StringColum
// make sure the user has SELECT privilege on all relevant columns of the underlying table
vetPrivileges();
-
- DerbyLuceneDir derbyLuceneDir = LuceneSupport.getDerbyLuceneDir( _connection, _schema, _table, _column );
+
+ String delimitedColumnName = LuceneSupport.delimitID( _column );
+ DerbyLuceneDir derbyLuceneDir = LuceneSupport.getDerbyLuceneDir( _connection, _schema, _table, delimitedColumnName );
StorageFile propertiesFile = LuceneSupport.getIndexPropertiesFile( derbyLuceneDir );
Properties indexProperties = readIndexProperties( propertiesFile );
String indexDescriptorMaker = indexProperties.getProperty( LuceneSupport.INDEX_DESCRIPTOR_MAKER );
@@ -522,9 +523,9 @@ class LuceneQueryVTI extends StringColum
for ( int i = 0; i < _maxKeyID; i++ )
{
if ( i > 0 ) { buffer.append( ", " ); }
- buffer.append( getColumnName( i + 1 ) );
+ buffer.append( LuceneSupport.delimitID( getColumnName( i + 1 ) ) );
}
- buffer.append( ", " + _column );
+ buffer.append( ", " + LuceneSupport.delimitID( _column ) );
buffer.append( " from " + LuceneSupport.makeTableName( _schema, _table ) );
buffer.append( " where 1=2" );
Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java?rev=1623782&r1=1623781&r2=1623782&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java Tue Sep 9 12:21:27 2014
@@ -518,7 +518,7 @@ public class LuceneSupport implements Op
for ( VTITemplate.ColumnDescriptor keyDesc : primaryKeys )
{
- String keyName = derbyIdentifier( keyDesc.columnName );
+ String keyName = delimitID( keyDesc.columnName );
if ( keyCount > 0 ) { query.append( ", " ); }
query.append( keyName );
@@ -540,7 +540,7 @@ public class LuceneSupport implements Op
}
query.append(", ");
- query.append( derbyIdentifier( textcol ) );
+ query.append( delimitID( derbyIdentifier( textcol ) ) );
query.append(" from " + makeTableName( schema, table ) );
ps = conn.prepareStatement( query.toString() );
@@ -1420,6 +1420,12 @@ public class LuceneSupport implements Op
catch (StandardException se) { throw sqlException( se ); }
}
+ /** Double quote an identifier in order to preserver casing */
+ static String delimitID( String id )
+ {
+ return IdUtil.normalToDelimited( id );
+ }
+
/** Raise an error if an argument is being given a null value */
static void checkNotNull( String argumentName, String argumentValue )
throws SQLException
@@ -1549,10 +1555,10 @@ public class LuceneSupport implements Op
for ( String key : keyColumns )
{
checkNotNull( "KEYCOLUMNS", key );
-
+
if ( counter > 0 ) { buffer.append( ", " ); }
counter++;
- buffer.append( derbyIdentifier( key ) );
+ buffer.append( delimitID( derbyIdentifier( key ) ) );
}
buffer.append( "\nfrom " + qualifiedName );
buffer.append( "\nwhere 1=2" );
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java?rev=1623782&r1=1623781&r2=1623782&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java Tue Sep 9 12:21:27 2014
@@ -1224,6 +1224,216 @@ public class LuceneSupportPermsTest exte
goodStatement( dboConnection, UNLOAD_TOOL );
}
+ /**
+ * <p>
+ * Test identifier casing for keys and text columns. See DERBY-6730.
+ * </p>
+ */
+ public void test_6730()
+ throws Exception
+ {
+ Connection dboConnection = openUserConnection( TEST_DBO );
+ Connection ruthConnection = openUserConnection( RUTH );
+
+ createSchema( ruthConnection, Types.INTEGER );
+ goodStatement
+ (
+ ruthConnection,
+ "create view v_6730_1 ( poemID, poemText ) as select poemID, poemText from ruth.poems"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "create view v_6730_2 ( poemID, \"poemText\" ) as select poemID, poemText from ruth.poems"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "create view v_6730_3 ( \"poemID\", poemText ) as select poemID, poemText from ruth.poems"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "create view v_6730_4 ( \"poemID\", \"poemText\" ) as select poemID, poemText from ruth.poems"
+ );
+
+ goodStatement( dboConnection, LOAD_TOOL );
+
+ // Index the views
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.createIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_1',\n" +
+ " 'poemText',\n" +
+ " null,\n" +
+ " 'poemID'\n" +
+ ")\n"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.createIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_2',\n" +
+ " '\"poemText\"',\n" +
+ " null,\n" +
+ " 'poemID'\n" +
+ ")\n"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.createIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_3',\n" +
+ " 'poemText',\n" +
+ " null,\n" +
+ " '\"poemID\"'\n" +
+ ")\n"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.createIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_4',\n" +
+ " '\"poemText\"',\n" +
+ " null,\n" +
+ " '\"poemID\"'\n" +
+ ")\n"
+ );
+
+ // Verify the expected casing of identifiers
+ vet6730( ruthConnection );
+
+ // Update the indexes and re-verify
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.updateIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_1',\n" +
+ " 'poemText',\n" +
+ " null\n" +
+ ")\n"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.updateIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_2',\n" +
+ " '\"poemText\"',\n" +
+ " null\n" +
+ ")\n"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.updateIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_3',\n" +
+ " 'poemText',\n" +
+ " null\n" +
+ ")\n"
+ );
+ goodStatement
+ (
+ ruthConnection,
+ "call luceneSupport.updateIndex\n" +
+ "(\n" +
+ " 'ruth',\n" +
+ " 'v_6730_4',\n" +
+ " '\"poemText\"',\n" +
+ " null\n" +
+ ")\n"
+ );
+ vet6730( ruthConnection );
+
+ goodStatement( ruthConnection, "call LuceneSupport.dropIndex( 'ruth', 'v_6730_1', 'poemText' )" );
+ goodStatement( ruthConnection, "call LuceneSupport.dropIndex( 'ruth', 'v_6730_2', '\"poemText\"' )" );
+ goodStatement( ruthConnection, "call LuceneSupport.dropIndex( 'ruth', 'v_6730_3', 'poemText' )" );
+ goodStatement( ruthConnection, "call LuceneSupport.dropIndex( 'ruth', 'v_6730_4', '\"poemText\"' )" );
+ goodStatement( dboConnection, UNLOAD_TOOL );
+ goodStatement( ruthConnection, "drop view v_6730_4" );
+ goodStatement( ruthConnection, "drop view v_6730_3" );
+ goodStatement( ruthConnection, "drop view v_6730_2" );
+ goodStatement( ruthConnection, "drop view v_6730_1" );
+ dropSchema( ruthConnection );
+ }
+ private void vet6730( Connection conn ) throws Exception
+ {
+ // Verify the expected casing of identifiers
+ String[][] expectedResults = new String[][]
+ {
+ { "5", "0.26756266" },
+ { "4", "0.22933942" },
+ { "3", "0.22933942" },
+ };
+ assertResults
+ (
+ conn,
+ "select i.poemID, i.score\n" +
+ "from table ( ruth.v_6730_1__poemText( 'star', 1000, null ) ) i\n" +
+ "order by i.score desc\n",
+ expectedResults,
+ false
+ );
+ assertResults
+ (
+ conn,
+ "select i.poemID, i.score\n" +
+ "from table ( ruth.\"V_6730_2__poemText\"( 'star', 1000, null ) ) i\n" +
+ "order by i.score desc\n",
+ expectedResults,
+ false
+ );
+ assertResults
+ (
+ conn,
+ "select i.\"poemID\", i.score\n" +
+ "from table ( ruth.v_6730_3__poemText( 'star', 1000, null ) ) i\n" +
+ "order by i.score desc\n",
+ expectedResults,
+ false
+ );
+ assertResults
+ (
+ conn,
+ "select i.\"poemID\", i.score\n" +
+ "from table ( ruth.\"V_6730_4__poemText\"( 'star', 1000, null ) ) i\n" +
+ "order by i.score desc\n",
+ expectedResults,
+ false
+ );
+
+ String[][] expectedListResults = new String[][]
+ {
+ { "RUTH", "V_6730_1", "POEMTEXT", "org.apache.lucene.analysis.en.EnglishAnalyzer" },
+ { "RUTH", "V_6730_2", "poemText", "org.apache.lucene.analysis.en.EnglishAnalyzer" },
+ { "RUTH", "V_6730_3", "POEMTEXT", "org.apache.lucene.analysis.en.EnglishAnalyzer" },
+ { "RUTH", "V_6730_4", "poemText", "org.apache.lucene.analysis.en.EnglishAnalyzer" },
+ };
+ assertResults
+ (
+ conn,
+ "select schemaName, tableName, columnName, analyzer\n" +
+ "from table( lucenesupport.listIndexes() ) t\n" +
+ "order by schemaName, tableName, columnName\n",
+ expectedListResults,
+ false
+ );
+ }
+
///////////////////////////////////////////////////////////////////////////////////
//
// MINIONS