@@ -3247,6 +3247,26 @@ private static void rollBackAndThrowSQLException(Connection conn,
32473247 throw se ;
32483248 }
32493249
3250+ /**
3251+ * given a row/column table, method returns size of table with samplePercentage=100%,
3252+ * if given an external table and sample percentage, method creates a column table with
3253+ * sample percentage amount and extrapolates memory for loading whole(100% data)
3254+ * external table as column table.
3255+ *
3256+ * Cases(Exceptions) not handled:
3257+ * Case 1: given a row/column table and isExternalTable=TRUE then it doesn't
3258+ * show an error instead it creates another column table with sample amount.
3259+ *
3260+ * Case 2: given an external table with isExternalTable=FALSE or
3261+ * given any table which is not present then it gives error but need to show
3262+ * an error message as table not found.
3263+ *
3264+ * @param tableName table name with schema(fully qualified table name)
3265+ * @param isExternalTable true for external table else false
3266+ * @param samplePercentage sampling percentage (Integer :0 to 100)
3267+ * @param tableSize returns resultset
3268+ * @throws SQLException
3269+ */
32503270 public static void GET_TABLE_SIZE (String tableName , Boolean isExternalTable , int samplePercentage , ResultSet [] tableSize ) throws SQLException {
32513271 if (GemFireXDUtils .TraceSysProcedures ) {
32523272 SanityManager .DEBUG_PRINT (GfxdConstants .TRACE_SYS_PROCEDURES ,
@@ -3258,34 +3278,34 @@ public static void GET_TABLE_SIZE(String tableName, Boolean isExternalTable, int
32583278
32593279 if (dataServers != null && dataServers .size () > 0 ) {
32603280 Map args = new HashMap <String , String >();
3261- if (isExternalTable ) {
3262- //create column table with same name
3263- float sample = ( float ) samplePercentage / 100 ;
3264- String sampleTable = tableName + "_sample" ;
3265- Connection conn = getDefaultConn ( );
3266- conn .createStatement ().execute ("create table " + sampleTable + " using column as(select * from " + tableName + " where rand() < " + sample + " );" );
3281+ if (isExternalTable ) {
3282+ float sample = ( float ) samplePercentage / 100 ;
3283+ String sampleTable = tableName + "_sample" ;
3284+ Connection conn = getDefaultConn () ;
3285+ conn . createStatement (). execute ( "drop table if exists " + sampleTable + " ;" );
3286+ conn .createStatement ().execute ("create table " + sampleTable + " using column as(select * from " + tableName + " where rand() < " + sample + " );" );
32673287 args .put ("TABLE_NAME" , sampleTable );
3268- }
3269- else {
3288+ } else {
32703289 args .put ("TABLE_NAME" , tableName );
3271- samplePercentage = 100 ;
3290+ samplePercentage = 100 ;
32723291 }
32733292 result = (ArrayList <SnappyRegionStatsCollectorResult >) FunctionService .onMembers (dataServers )
32743293 .withArgs (args )
32753294 .execute (SnappyRegionStatsCollectorFunction .ID ).getResult (1 , TimeUnit .SECONDS );
32763295
32773296 List <SnappyRegionStats > stats = ((SnappyRegionStatsCollectorResult ) result .get (0 )).getRegionStats ();
32783297 SnappyRegionStats statsResult = stats .get (0 );
3279- long sampleTableSize = statsResult .getTotalSize ();
3280- long sampleInMemoryTableSize = statsResult .getSizeInMemory ();
3298+ long sampleTableSize = statsResult .getTotalSize ();
3299+ long sampleInMemoryTableSize = statsResult .getSizeInMemory ();
32813300
3282- final long totalTableSize = (sampleTableSize * 100 )/ samplePercentage ;
3283- final long inMemoryTableSize = (sampleInMemoryTableSize * 100 )/ samplePercentage ;
3301+ final long totalTableSize = (sampleTableSize * 100 ) / samplePercentage ;
3302+ final long inMemoryTableSize = (sampleInMemoryTableSize * 100 ) / samplePercentage ;
32843303
32853304 Boolean resultFetched = true ;
32863305 final CustomRowsResultSet .FetchDVDRows fetchRows =
32873306 new CustomRowsResultSet .FetchDVDRows () {
32883307 Boolean resultFetched = false ;
3308+
32893309 @ Override
32903310 public boolean getNext (DataValueDescriptor [] template )
32913311 throws SQLException , StandardException {
@@ -3322,16 +3342,16 @@ public boolean getNext(DataValueDescriptor[] template)
33223342 }
33233343 }
33243344 } catch (InterruptedException e ) {
3325- e .printStackTrace (); // todo remove printStackTrace
3345+ e .printStackTrace ();
33263346 } catch (StandardException se ) {
33273347 se .printStackTrace ();
33283348 }
33293349 }
33303350
33313351 private static final ResultColumnDescriptor [] tableSizeInfo = {
3332- EmbedResultSetMetaData .getResultColumnDescriptor ("TOTAL_TABLE_SIZE " , Types .VARCHAR ,
3352+ EmbedResultSetMetaData .getResultColumnDescriptor ("TOTAL TABLE SIZE " , Types .VARCHAR ,
33333353 false , Limits .DB2_VARCHAR_MAXWIDTH ),
3334- EmbedResultSetMetaData .getResultColumnDescriptor ("IN_MEMORY_TABLE_SIZE " , Types .VARCHAR ,
3354+ EmbedResultSetMetaData .getResultColumnDescriptor ("IN MEMORY TABLE SIZE " , Types .VARCHAR ,
33353355 false , Limits .DB2_VARCHAR_MAXWIDTH )
33363356 };
33373357
0 commit comments