Fix Exception error when preview data on datamart data set data using attached CSV Flat File as Data Source. [36920]
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java
index af56aaf..3739a46 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/QueryTestBase.java
@@ -19,6 +19,7 @@
import org.eclipse.datatools.connectivity.oda.flatfile.CommonConstants;
import org.eclipse.datatools.connectivity.oda.flatfile.Connection;
import org.eclipse.datatools.connectivity.oda.flatfile.FlatFileQuery;
+import org.eclipse.datatools.connectivity.oda.flatfile.util.querytextutil.QueryTextUtil;
import junit.framework.TestCase;
@@ -68,25 +69,35 @@
* @param includeTypeLine
* @throws OdaException
*/
- public void executeQueryTest( IResultSet resultSet, boolean includeTypeLine )
+ public void executeQueryTest( IResultSet resultSet, boolean includeTypeLine, boolean validateCols )
throws OdaException
{
- assertEquals( 3, resultSet.getMetaData( ).getColumnCount( ) );
- assertEquals( includeTypeLine ? "INT" : "STRING",
- resultSet.getMetaData( ).getColumnTypeName( 1 ).toUpperCase( ) );
- assertEquals( includeTypeLine ? "TIMESTAMP" : "STRING",
- resultSet.getMetaData( ).getColumnTypeName( 2 ).toUpperCase( ) );
- assertEquals( includeTypeLine ? "STRING" : "STRING",
- resultSet.getMetaData( )
- .getColumnTypeName( 3 )
- .toUpperCase( )
- .toUpperCase( ) );
+ if (validateCols)
+ {
+ assertEquals( 3, resultSet.getMetaData( ).getColumnCount( ) );
+ assertEquals( includeTypeLine ? "INT" : "STRING",
+ resultSet.getMetaData( ).getColumnTypeName( 1 ).toUpperCase( ) );
+ assertEquals( includeTypeLine ? "TIMESTAMP" : "STRING",
+ resultSet.getMetaData( ).getColumnTypeName( 2 ).toUpperCase( ) );
+ assertEquals( includeTypeLine ? "STRING" : "STRING",
+ resultSet.getMetaData( )
+ .getColumnTypeName( 3 )
+ .toUpperCase( )
+ .toUpperCase( ) );
+ }
+
int id = 1;
while ( resultSet.next( ) )
{
assertEquals( resultSet.getRow( ), id++ );
}
}
+
+ public void executeQueryTest( IResultSet resultSet, boolean includeTypeLine )
+ throws OdaException
+ {
+ executeQueryTest( resultSet, includeTypeLine, true );
+ }
/**
*
@@ -427,7 +438,7 @@
protected abstract String getDelimiter( );
protected abstract String getDelimiterName( );
-
+
/**
*
* @return
@@ -435,4 +446,64 @@
protected abstract String getSuffix( );
protected abstract String getExtension( );
+
+ /**
+ * Test query parsing logic.
+ */
+ public void testCompliateNames( )
+ {
+ try
+ {
+ setUpwithColunmNameSpecified();
+ }
+ catch ( OdaException ex )
+ {
+ ex.printStackTrace( );
+ fail( ex.getMessage( ) );
+ }
+
+ for (String tab : TestUtil.COMPLICATE_TAB_NAMES)
+ {
+ try
+ {
+ String query = "select "
+ + "\"" + TestUtil.COMPLICATE_TAB_COLNAMES[0] + "\",\""
+ + TestUtil.COMPLICATE_TAB_COLNAMES[1] + "\",\""
+ + TestUtil.COMPLICATE_TAB_COLNAMES[2] + "\",\""
+ + TestUtil.COMPLICATE_TAB_COLNAMES[3] + "\" from "
+ + "\"" + tab + getSuffix( ) + getExtension( ) + "\"";
+
+ String[] queryMetaData = QueryTextUtil.getQueryMetaData( query );
+
+ assertTrue( tab.equalsIgnoreCase( queryMetaData[2].substring( 0,
+ tab.length( ) ) ) );
+
+ String[] cols = queryMetaData[0].split( "," );
+ for ( int i = 0; i < cols.length; i++ )
+ {
+ assertTrue( TestUtil.COMPLICATE_TAB_COLNAMES[i].equalsIgnoreCase( QueryTextUtil.getUnQuotedName( cols[i] ) ) );
+ }
+
+ statement.prepare( query );
+ IResultSet resultSet = statement.executeQuery( );
+
+ assertEquals( 4, resultSet.getMetaData( ).getColumnCount( ) );
+ assertTrue( TestUtil.COMPLICATE_TAB_COLNAMES[0].equalsIgnoreCase( resultSet.getMetaData( )
+ .getColumnName( 1 ) ) );
+ assertTrue( TestUtil.COMPLICATE_TAB_COLNAMES[1].equalsIgnoreCase( resultSet.getMetaData( )
+ .getColumnName( 2 ) ) );
+ assertTrue( TestUtil.COMPLICATE_TAB_COLNAMES[2].equalsIgnoreCase( resultSet.getMetaData( )
+ .getColumnName( 3 ) ) );
+ assertTrue( TestUtil.COMPLICATE_TAB_COLNAMES[3].equalsIgnoreCase( resultSet.getMetaData( )
+ .getColumnName( 4 ) ) );
+
+ executeQueryTest( resultSet, false, false );
+ }
+ catch ( OdaException ex )
+ {
+ ex.printStackTrace( );
+ fail( ex.getMessage( ) );
+ }
+ }
+ }
}
diff --git a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java
index eecbbd2..5265c96 100644
--- a/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java
+++ b/tests/org.eclipse.datatools.connectivity.oda.flatfile.tests/src/org/eclipse/datatools/connectivity/oda/flatfile/tests/TestUtil.java
@@ -47,6 +47,21 @@
public static int HUGE_TABLE_ROW_COUNT = 2 * FlatFileDataReader.MAX_ROWS_PER_FETCH + 5;
+ public static String[] COMPLICATE_TAB_NAMES = {
+ "table_complicateColName1",
+ "table_complicate Col Name2",
+ "table_complicate Col Name3 from name2",
+ "table_complicate Col Name4 from",
+ "from table_complicate Col Name5 from from name4"
+ };
+
+ public static String[] COMPLICATE_TAB_COLNAMES = {
+ "INT COL from Integer",
+ "Double coL from from double",
+ "from int to int from from int",
+ "from int to int from from int from"
+ };
+
/**
*
* @param delimiter
@@ -79,6 +94,7 @@
createTestFile_test12( path, delimiter );
createTestFile_test13( path, delimiter );
createTestFile_hugeRows( path, delimiter );
+ createTestFile_compliateColName( path, delimiter );
}
@@ -904,4 +920,58 @@
file.deleteOnExit( );
}
+ private static void createTestFile_compliateColName( String path,
+ String delimiter ) throws OdaException
+ {
+ for (String name: COMPLICATE_TAB_NAMES)
+ {
+ generateComplicateNameData(path, name, delimiter);
+ }
+ System.out.println();
+ }
+
+ private static void generateComplicateNameData( String path, String name,
+ String delimiter ) throws OdaException
+ {
+ File file = new File( path
+ + File.separator + name + getSuffix( delimiter )
+ + fileExtension );
+ if ( file.exists( ) )
+ {
+ file.deleteOnExit( );
+ return;
+ }
+ try
+ {
+ FileOutputStream fos = new FileOutputStream( file );
+ OutputStreamWriter osw = new OutputStreamWriter( fos, DATASET );
+
+ Random r = new Random( );
+ String endOfLine = new String( "\n" );
+ osw.flush( );
+ String header = "INT COL from Integer"
+ + delimiter + "Double coL from from double" + delimiter
+ + "from int to int from from int" + delimiter
+ + "from int to int from from int from" + "\n";
+ osw.write( header );
+ for ( int i = 0; i < 10; i++ )
+ {
+ osw.write( Integer.toString( i + 1 ));
+ osw.write( delimiter );
+ osw.write( Double.toString( r.nextDouble( ) ) );
+ osw.write( delimiter );
+ osw.write( Integer.toString( r.nextInt( ) ) );
+ osw.write( delimiter );
+ osw.write( Integer.toString( r.nextInt( ) ) );
+ osw.write( endOfLine );
+ }
+ osw.close( );
+ }
+ catch ( Exception e )
+ {
+ throw new OdaException( e.getMessage( ) );
+ }
+ file.deleteOnExit( );
+ }
+
}
\ No newline at end of file