AnalyticsSqlUtils { public static String getClosingParentheses( String str ) { if ( StringUtils.isEmpty( str ) ) { return StringUtils.EMPTY; } int open = 0; for ( int i = 0; i < str.length(); i++ ) { if ( str.charAt( i ) == '(' ) { open++; } else if ( str.charAt( i ) == ')' ) { if ( open >= 1 ) { open--; } } } return StringUtils.repeat( ")", open ); }  static String quote( String relation ); static String quote( String alias, String relation ); static String quoteAlias( String relation ); static String removeQuote( String relation ); static String encode( String value, boolean quote ); static String getClosingParentheses( String str ); static final String QUOTE; static final String SINGLE_QUOTE; static final String ANALYTICS_TBL_ALIAS; static final String DATE_PERIOD_STRUCT_ALIAS; static final String ORG_UNIT_STRUCT_ALIAS; }
@Test public void testGetClosingParentheses() { assertThat( AnalyticsSqlUtils.getClosingParentheses( null ), is( "" ) ); assertThat( AnalyticsSqlUtils.getClosingParentheses( "" ), is( "" ) ); assertThat( AnalyticsSqlUtils.getClosingParentheses( "from(select(select (*))" ), is( ")" ) ); assertThat( AnalyticsSqlUtils.getClosingParentheses( "((" ), is( "))" ) ); assertThat( AnalyticsSqlUtils.getClosingParentheses( "ckwk3rkwptp2)2upywjnmne0o92ylzf4rw(5arbll1c0qrawpdh8n(89h)57r8j7er6qc1vnghnmsx4mssa77idrcrwcx0tuh359" ), is( ")" ) ); }