Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E025D11122 for ; Tue, 9 Sep 2014 12:21:53 +0000 (UTC) Received: (qmail 55081 invoked by uid 500); 9 Sep 2014 12:21:53 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 55054 invoked by uid 500); 9 Sep 2014 12:21:53 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 55045 invoked by uid 99); 9 Sep 2014 12:21:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Sep 2014 12:21:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Sep 2014 12:21:30 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3552A238899C; Tue, 9 Sep 2014 12:21:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1623782 - in /db/derby/code/trunk/java: optional/org/apache/derby/optional/lucene/ testing/org/apache/derbyTesting/functionTests/tests/lang/ Date: Tue, 09 Sep 2014 12:21:28 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140909122128.3552A238899C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 ); } + /** + *

+ * Test identifier casing for keys and text columns. See DERBY-6730. + *

+ */ + 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