public void testConvertA() { TextSplitter splitter = new TextSplitter(); String out = splitter.bigDecimalToString(splitter.stringToBigDecimal("A")); assertEquals("A", out); }
List<String> split(int numSplits, String minString, String maxString, String commonPrefix) throws SQLException { BigDecimal minVal = stringToBigDecimal(minString); BigDecimal maxVal = stringToBigDecimal(maxString); List<BigDecimal> splitPoints = split(new BigDecimal(numSplits), minVal, maxVal); List<String> splitStrings = new ArrayList<String>(); // Convert the BigDecimal splitPoints into their string representations. for (BigDecimal bd : splitPoints) { splitStrings.add(commonPrefix + bigDecimalToString(bd)); } // Make sure that our user-specified boundaries are the first and last entries // in the array. if (splitStrings.size() == 0 || !splitStrings.get(0).equals(commonPrefix + minString)) { splitStrings.add(0, commonPrefix + minString); } if (splitStrings.size() == 1 || !splitStrings.get(splitStrings.size() - 1).equals(commonPrefix + maxString)) { splitStrings.add(commonPrefix + maxString); } return splitStrings; }
/** * Return a BigDecimal representation of string 'str' suitable for use * in a numerically-sorting order. */ BigDecimal stringToBigDecimal(String str) { BigDecimal result = BigDecimal.ZERO; BigDecimal curPlace = ONE_PLACE; // start with 1/65536 to compute the first digit. int len = Math.min(str.length(), MAX_CHARS); for (int i = 0; i < len; i++) { int codePoint = str.codePointAt(i); result = result.add(tryDivide(new BigDecimal(codePoint), curPlace)); // advance to the next less significant place. e.g., 1/(65536^2) for the second char. curPlace = curPlace.multiply(ONE_PLACE); } return result; }
@Test(timeout=2000) public void testTextSplitter() throws Exception{ TextSplitter splitter = new TextSplitter(); ResultSet result = mock(ResultSet.class); List<InputSplit> splits = splitter.split(configuration, result, "column"); assertSplits(new String[] {"column IS NULL column IS NULL"}, splits); when(result.getString(1)).thenReturn("result1"); when(result.getString(2)).thenReturn("result2"); splits = splitter.split(configuration, result, "column1"); assertSplits(new String[] {"column1 >= 'result1' column1 < 'result1.'", "column1 >= 'result1' column1 <= 'result2'"}, splits); }
public void testBigDecConvertEmpty() { TextSplitter splitter = new TextSplitter(); String emptyStr = splitter.bigDecimalToString(BigDecimal.ZERO); assertEquals("", emptyStr); }
public void testStringConvertEmpty() { TextSplitter splitter = new TextSplitter(); BigDecimal emptyBigDec = splitter.stringToBigDecimal(""); assertEquals(BigDecimal.ZERO, emptyBigDec); }
case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter();
maxString = maxString.substring(sharedLen); List<String> splitStrings = split(numSplits, minString, maxString, commonPrefix); List<InputSplit> splits = new ArrayList<InputSplit>();
public void testAlphabetSplit() throws SQLException { // This should give us 25 splits, one per letter. TextSplitter splitter = new TextSplitter(); List<String> splits = splitter.split(25, "A", "Z", ""); String [] expected = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; assertArrayEquals(expected, splits.toArray(new String [0])); }
public void testStringConvertEmpty() { TextSplitter splitter = new TextSplitter(); BigDecimal emptyBigDec = splitter.stringToBigDecimal(""); assertEquals(BigDecimal.ZERO, emptyBigDec); }
public void testBigDecConvertEmpty() { TextSplitter splitter = new TextSplitter(); String emptyStr = splitter.bigDecimalToString(BigDecimal.ZERO); assertEquals("", emptyStr); }
case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter();
maxString = maxString.substring(sharedLen); List<String> splitStrings = split(numSplits, minString, maxString, commonPrefix); List<InputSplit> splits = new ArrayList<InputSplit>();
public void testConvertChomped() { TextSplitter splitter = new TextSplitter(); String out = splitter.bigDecimalToString(splitter.stringToBigDecimal("AVeryLongStringIndeed")); assertEquals("AVeryLon", out); }
List<String> split(int numSplits, String minString, String maxString, String commonPrefix) throws SQLException { BigDecimal minVal = stringToBigDecimal(minString); BigDecimal maxVal = stringToBigDecimal(maxString); List<BigDecimal> splitPoints = split(new BigDecimal(numSplits), minVal, maxVal); List<String> splitStrings = new ArrayList<String>(); // Convert the BigDecimal splitPoints into their string representations. for (BigDecimal bd : splitPoints) { splitStrings.add(commonPrefix + bigDecimalToString(bd)); } // Make sure that our user-specified boundaries are the first and last entries // in the array. if (splitStrings.size() == 0 || !splitStrings.get(0).equals(commonPrefix + minString)) { splitStrings.add(0, commonPrefix + minString); } if (splitStrings.size() == 1 || !splitStrings.get(splitStrings.size() - 1).equals(commonPrefix + maxString)) { splitStrings.add(commonPrefix + maxString); } return splitStrings; }
public void testCommonPrefix() throws SQLException { // Splits between 'Hand' and 'Hardy' TextSplitter splitter = new TextSplitter(); List<String> splits = splitter.split(5, "nd", "rdy", "Ha"); // Don't check for exact values in the middle, because the splitter generates some // ugly Unicode-isms. But do check that we get multiple splits and that it starts // and ends on the correct points. assertEquals("Hand", splits.get(0)); assertEquals("Hardy", splits.get(splits.size() -1)); assertEquals(6, splits.size()); } }
case Types.VARCHAR: case Types.LONGVARCHAR: return new TextSplitter();
maxString = maxString.substring(sharedLen); List<String> splitStrings = split(numSplits, minString, maxString, commonPrefix); List<InputSplit> splits = new ArrayList<InputSplit>();
/** * Return a BigDecimal representation of string 'str' suitable for use * in a numerically-sorting order. */ BigDecimal stringToBigDecimal(String str) { BigDecimal result = BigDecimal.ZERO; BigDecimal curPlace = ONE_PLACE; // start with 1/65536 to compute the first digit. int len = Math.min(str.length(), MAX_CHARS); for (int i = 0; i < len; i++) { int codePoint = str.codePointAt(i); result = result.add(tryDivide(new BigDecimal(codePoint), curPlace)); // advance to the next less significant place. e.g., 1/(65536^2) for the second char. curPlace = curPlace.multiply(ONE_PLACE); } return result; }
public void testConvertThreeChars() { TextSplitter splitter = new TextSplitter(); String out = splitter.bigDecimalToString(splitter.stringToBigDecimal("abc")); assertEquals("abc", out); }