protected String formatDDLStatement ( String sql ) { String result = removeComments ( sql ) ; String [ ] parts = getTokens ( sql , 0 ) ; if ( parts . length > 2 && parts [ 0 ] . equalsIgnoreCase ( "create" ) && parts [ 1 ] . equalsIgnoreCase ( "table" ) ) { String sqlWithSingleSpaces = String . join ( " " , parts ) ; int primaryKeyIndex = sqlWithSingleSpaces . toUpperCase ( ) . indexOf ( ", PRIMARY KEY (" ) ; if ( primaryKeyIndex > - 1 ) { int endPrimaryKeyIndex = sqlWithSingleSpaces . indexOf ( ' ' , primaryKeyIndex ) ; String primaryKeySpec = sqlWithSingleSpaces . substring ( primaryKeyIndex + 2 , endPrimaryKeyIndex + 1 ) ; sqlWithSingleSpaces = sqlWithSingleSpaces . replace ( ", " + primaryKeySpec , "" ) ; sqlWithSingleSpaces = sqlWithSingleSpaces + " " + primaryKeySpec ; result = sqlWithSingleSpaces . replaceAll ( "\\s+\\)" , ")" ) ; } } return result ; }
Does some formatting to DDL statements that might have been generated by standard SQL generators to make it compatible with Google Cloud Spanner . We also need to get rid of any comments as Google Cloud Spanner does not accept comments in DDL - statements .