target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test(expected=NullPointerException.class) public void testNullCalendar() throws InvalidAccessException { accessor.getDate(0, null); } | @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } DateMilliAccessor(DateMilliVector vector, TimeZone defaultTZ); } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } DateMilliAccessor(DateMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Date getDate(int index, Calendar calendar); } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } DateMilliAccessor(DateMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Date getDate(int index, Calendar calendar); } |
@Test public void testGetDate() throws Exception { assertEquals(new Date(72, 10, 3), accessor.getDate(0, PST_CALENDAR)); assertEquals(new Date(72, 10, 4), accessor.getDate(0, UTC_CALENDAR)); assertEquals(new Date(119, 4, 27), accessor.getDate(1, PST_CALENDAR)); assertEquals(new Date(119, 4, 27), accessor.getDate(1, UTC_CALENDAR)); } | @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } DateMilliAccessor(DateMilliVector vector, TimeZone defaultTZ); } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } DateMilliAccessor(DateMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Date getDate(int index, Calendar calendar); } | DateMilliAccessor extends AbstractSqlAccessor { @Override public Date getDate(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve date."); return getDate(index, calendar.getTimeZone()); } DateMilliAccessor(DateMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Date getDate(int index, Calendar calendar); } |
@Test public void testIsNull() throws Exception { assertFalse(genericAccessor.isNull(0)); assertTrue(genericAccessor.isNull(1)); } | @Override public boolean isNull(int index) { return v.isNull(index); } | GenericAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return v.isNull(index); } } | GenericAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return v.isNull(index); } GenericAccessor(ValueVector v); } | GenericAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return v.isNull(index); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } | GenericAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return v.isNull(index); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } |
@Test public void testGetObject() throws Exception { assertEquals(NON_NULL_VALUE, genericAccessor.getObject(0)); assertNull(genericAccessor.getObject(1)); } | @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } GenericAccessor(ValueVector v); } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } |
@Test(expected=IndexOutOfBoundsException.class) public void testGetObject_indexOutOfBounds() throws Exception { genericAccessor.getObject(2); } | @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } GenericAccessor(ValueVector v); } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } | GenericAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) throws InvalidAccessException { return v.getObject(index); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } |
@Test public void testGetType() throws Exception { assertEquals(UserBitShared.SerializedField.getDefaultInstance().getMajorType(), genericAccessor.getType()); } | @Override public MajorType getType() { return getMajorTypeForField(v.getField()); } | GenericAccessor extends AbstractSqlAccessor { @Override public MajorType getType() { return getMajorTypeForField(v.getField()); } } | GenericAccessor extends AbstractSqlAccessor { @Override public MajorType getType() { return getMajorTypeForField(v.getField()); } GenericAccessor(ValueVector v); } | GenericAccessor extends AbstractSqlAccessor { @Override public MajorType getType() { return getMajorTypeForField(v.getField()); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } | GenericAccessor extends AbstractSqlAccessor { @Override public MajorType getType() { return getMajorTypeForField(v.getField()); } GenericAccessor(ValueVector v); @Override Class<?> getObjectClass(); @Override boolean isNull(int index); @Override Object getObject(int index); @Override MajorType getType(); } |
@Test public void testIsNull() throws Exception { assertNotNull(accessor.getObject(0)); assertNotNull(accessor.getTimestamp(0, PST_CALENDAR)); assertNull(accessor.getObject(2)); assertNull(accessor.getTimestamp(2, PST_CALENDAR)); } | @Override public boolean isNull(int index) { return ac.isNull(index); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return ac.isNull(index); } } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return ac.isNull(index); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return ac.isNull(index); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public boolean isNull(int index) { return ac.isNull(index); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } |
@Test public void testGetObject() throws Exception { assertEquals( new Timestamp(72, 10, 4, 11, 10, 8, (int)TimeUnit.MILLISECONDS.toNanos(957)), accessor.getObject(0)); } | @Override public Object getObject(int index) { return getTimestamp(index, defaultTimeZone); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) { return getTimestamp(index, defaultTimeZone); } } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) { return getTimestamp(index, defaultTimeZone); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) { return getTimestamp(index, defaultTimeZone); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Object getObject(int index) { return getTimestamp(index, defaultTimeZone); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } |
@Test(expected=NullPointerException.class) public void testNullCalendar() throws InvalidAccessException { accessor.getTimestamp(0, null); } | @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } |
@Test public void ruleSuggestionsSelectNumberAtBeginning() { Selection selection = new Selection("col", "883 N Shoreline Blvd, Mountain View, CA 94043", 0, 3); List<ReplacePatternRule> rules = recommender.getRules(selection, TEXT); assertEquals(3, rules.size()); compare(ReplaceSelectionType.CONTAINS, "883", false, rules.get(0)); compare(ReplaceSelectionType.STARTS_WITH, "883", false, rules.get(1)); compare(ReplaceSelectionType.MATCHES, "\\d+", false, rules.get(2)); } | @Override public List<ReplacePatternRule> getRules(Selection selection, DataType selColType) { Preconditions.checkArgument(selColType == DataType.TEXT, "Cards generation for Replace/Keeponly/Exclude transforms is supported only on TEXT type columns"); List<ReplacePatternRule> rules = new ArrayList<>(); if (selection.getCellText() == null) { rules.add(new ReplacePatternRule(IS_NULL)); } else { final int start = selection.getOffset(); final int end = start + selection.getLength(); final String content = selection.getCellText().substring(start, end); if (content.length() > 0) { rules.addAll(casePermutations(CONTAINS, content)); if (start == 0) { rules.addAll(casePermutations(STARTS_WITH, content)); } if (end == selection.getCellText().length()) { rules.addAll(casePermutations(ENDS_WITH, content)); } List<String> patterns = recommendReplacePattern(selection); for (String pattern : patterns) { rules.add(new ReplacePatternRule(MATCHES).setSelectionPattern(pattern)); } } if (start == 0 && end == selection.getCellText().length()) { rules.addAll(casePermutations(EXACT, content)); } } return rules; } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { @Override public List<ReplacePatternRule> getRules(Selection selection, DataType selColType) { Preconditions.checkArgument(selColType == DataType.TEXT, "Cards generation for Replace/Keeponly/Exclude transforms is supported only on TEXT type columns"); List<ReplacePatternRule> rules = new ArrayList<>(); if (selection.getCellText() == null) { rules.add(new ReplacePatternRule(IS_NULL)); } else { final int start = selection.getOffset(); final int end = start + selection.getLength(); final String content = selection.getCellText().substring(start, end); if (content.length() > 0) { rules.addAll(casePermutations(CONTAINS, content)); if (start == 0) { rules.addAll(casePermutations(STARTS_WITH, content)); } if (end == selection.getCellText().length()) { rules.addAll(casePermutations(ENDS_WITH, content)); } List<String> patterns = recommendReplacePattern(selection); for (String pattern : patterns) { rules.add(new ReplacePatternRule(MATCHES).setSelectionPattern(pattern)); } } if (start == 0 && end == selection.getCellText().length()) { rules.addAll(casePermutations(EXACT, content)); } } return rules; } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { @Override public List<ReplacePatternRule> getRules(Selection selection, DataType selColType) { Preconditions.checkArgument(selColType == DataType.TEXT, "Cards generation for Replace/Keeponly/Exclude transforms is supported only on TEXT type columns"); List<ReplacePatternRule> rules = new ArrayList<>(); if (selection.getCellText() == null) { rules.add(new ReplacePatternRule(IS_NULL)); } else { final int start = selection.getOffset(); final int end = start + selection.getLength(); final String content = selection.getCellText().substring(start, end); if (content.length() > 0) { rules.addAll(casePermutations(CONTAINS, content)); if (start == 0) { rules.addAll(casePermutations(STARTS_WITH, content)); } if (end == selection.getCellText().length()) { rules.addAll(casePermutations(ENDS_WITH, content)); } List<String> patterns = recommendReplacePattern(selection); for (String pattern : patterns) { rules.add(new ReplacePatternRule(MATCHES).setSelectionPattern(pattern)); } } if (start == 0 && end == selection.getCellText().length()) { rules.addAll(casePermutations(EXACT, content)); } } return rules; } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { @Override public List<ReplacePatternRule> getRules(Selection selection, DataType selColType) { Preconditions.checkArgument(selColType == DataType.TEXT, "Cards generation for Replace/Keeponly/Exclude transforms is supported only on TEXT type columns"); List<ReplacePatternRule> rules = new ArrayList<>(); if (selection.getCellText() == null) { rules.add(new ReplacePatternRule(IS_NULL)); } else { final int start = selection.getOffset(); final int end = start + selection.getLength(); final String content = selection.getCellText().substring(start, end); if (content.length() > 0) { rules.addAll(casePermutations(CONTAINS, content)); if (start == 0) { rules.addAll(casePermutations(STARTS_WITH, content)); } if (end == selection.getCellText().length()) { rules.addAll(casePermutations(ENDS_WITH, content)); } List<String> patterns = recommendReplacePattern(selection); for (String pattern : patterns) { rules.add(new ReplacePatternRule(MATCHES).setSelectionPattern(pattern)); } } if (start == 0 && end == selection.getCellText().length()) { rules.addAll(casePermutations(EXACT, content)); } } return rules; } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { @Override public List<ReplacePatternRule> getRules(Selection selection, DataType selColType) { Preconditions.checkArgument(selColType == DataType.TEXT, "Cards generation for Replace/Keeponly/Exclude transforms is supported only on TEXT type columns"); List<ReplacePatternRule> rules = new ArrayList<>(); if (selection.getCellText() == null) { rules.add(new ReplacePatternRule(IS_NULL)); } else { final int start = selection.getOffset(); final int end = start + selection.getLength(); final String content = selection.getCellText().substring(start, end); if (content.length() > 0) { rules.addAll(casePermutations(CONTAINS, content)); if (start == 0) { rules.addAll(casePermutations(STARTS_WITH, content)); } if (end == selection.getCellText().length()) { rules.addAll(casePermutations(ENDS_WITH, content)); } List<String> patterns = recommendReplacePattern(selection); for (String pattern : patterns) { rules.add(new ReplacePatternRule(MATCHES).setSelectionPattern(pattern)); } } if (start == 0 && end == selection.getCellText().length()) { rules.addAll(casePermutations(EXACT, content)); } } return rules; } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test public void testGetTimestamp() throws Exception { assertEquals( new Timestamp(72, 10, 4, 3, 10, 8, (int)TimeUnit.MILLISECONDS.toNanos(957)), accessor.getTimestamp(0, PST_CALENDAR)); assertEquals( new Timestamp(72, 10, 4, 11, 10, 8, (int)TimeUnit.MILLISECONDS.toNanos(957)), accessor.getTimestamp(0, UTC_CALENDAR)); assertEquals( new Timestamp(119, 4, 27, 16, 33, 13, (int)TimeUnit.MILLISECONDS.toNanos(123)), accessor.getTimestamp(1, PST_CALENDAR)); assertEquals( new Timestamp(119, 4, 27, 23, 33, 13, (int)TimeUnit.MILLISECONDS.toNanos(123)), accessor.getTimestamp(1, UTC_CALENDAR)); } | @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } | TimeStampMilliAccessor extends AbstractSqlAccessor { @Override public Timestamp getTimestamp(int index, Calendar calendar) { Preconditions.checkNotNull(calendar, "Invalid calendar used when attempting to retrieve timestamp."); return getTimestamp(index, calendar.getTimeZone()); } TimeStampMilliAccessor(TimeStampMilliVector vector, TimeZone defaultTZ); @Override MajorType getType(); @Override boolean isNull(int index); @Override Class<?> getObjectClass(); @Override Object getObject(int index); @Override Timestamp getTimestamp(int index, Calendar calendar); } |
@Test public void test_connect_declinesNonDremioJdbcUrl() throws SQLException { assertThat( uut.connect( "jdbc:somedb:whatever", null ), nullValue() ); } | @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void test_connect_declinesNotQuiteDremioUrl() throws SQLException { assertThat( uut.connect( "jdbc:dremio", null ), nullValue() ); } | @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Ignore( "Just hangs, trying to connect to non-existent local zookeeper." ) @Test public void test_connect_acceptsMinimalDremioJdbcUrl() throws SQLException { assertThat( uut.connect( "jdbc:dremio:", null ), nullValue() ); fail( "Not implemented yet" ); } | @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Ignore( "Just hangs, trying to connect to non-existent local zookeeper." ) @Test public void test_connect_DECIDEWHICHBogusDremioJdbcUrl() throws SQLException { assertThat( uut.connect( "jdbc:dremio:x=y;z;;a=b=c=d;what=ever", null ), nullValue() ); fail( "Not implemented yet" ); } | @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public Connection connect( String url, Properties info ) throws SQLException { return impl.connect( url, info ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void test_acceptsURL_acceptsDremioUrlMinimal() throws SQLException { assertThat( uut.acceptsURL("jdbc:dremio:"), equalTo( true ) ); } | @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void test_acceptsURL_acceptsDremioPlusJunk() throws SQLException { assertThat( uut.acceptsURL("jdbc:dremio:should it check this?"), equalTo( true ) ); } | @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void contains() throws Exception { final File dataFile = temp.newFile("containsTest.json"); try (final PrintWriter printWriter = new PrintWriter(dataFile)) { printWriter.append("{ \"col\" : \"This is an amazing restaurant. Very good food.\" }"); printWriter.append("{ \"col\" : \"This is a worst restaurant. bad food.\" }"); printWriter.append("{ \"col\" : \"Amazing environment. \\nAmazing food.\" }"); printWriter.append("{ \"col\" : \"Not good.\" }"); } ReplacePatternRule rule = new ReplacePatternRule(ReplaceSelectionType.CONTAINS) .setSelectionPattern("amazing"); TransformRuleWrapper<ReplacePatternRule> ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'CONTAINS', 'amazing', false)", "CASE WHEN regexp_like(\"input.expr\", '.*?\\Qamazing\\E.*?') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '.*?\\Qamazing\\E.*?') THEN " + "regexp_replace(\"input.expr\", '\\Qamazing\\E', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '.*?\\Qamazing\\E.*?') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '.*?\\Qamazing\\E.*?')" ); List<Object> outputSelReplace = list( (Object)"This is an AMAZING restaurant. Very good food.", "This is a worst restaurant. bad food.", "Amazing environment. \nAmazing food.", "Not good." ); List<Object> outputCompleteReplace = list( (Object)"AMAZING", "This is a worst restaurant. bad food.", "Amazing environment. \nAmazing food.", "Not good." ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "AMAZING"}, outputSelReplace, asList(true, false, false, false), asList(asList(new CardExamplePosition(11, 7)), null, null, null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "AMAZING"}, outputCompleteReplace, asList(true, false, false, false), asList(asList(new CardExamplePosition(11, 7)), null, null, null) ); rule = rule.setIgnoreCase(true); ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'CONTAINS', 'amazing', true)", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?\\Qamazing\\E.*?') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?\\Qamazing\\E.*?') THEN " + "regexp_replace(\"input.expr\", '(?i)(?u)\\Qamazing\\E', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?\\Qamazing\\E.*?') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '(?i)(?u).*?\\Qamazing\\E.*?')" ); outputSelReplace = list( (Object)"This is an AMAZING restaurant. Very good food.", "This is a worst restaurant. bad food.", "AMAZING environment. \nAMAZING food.", "Not good." ); outputCompleteReplace = list( (Object)"AMAZING", "This is a worst restaurant. bad food.", "AMAZING", "Not good." ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "AMAZING"}, outputSelReplace, asList(true, false, true, false), asList(asList(new CardExamplePosition(11, 7)), null, asList(new CardExamplePosition(0, 7)), null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "AMAZING"}, outputCompleteReplace, asList(true, false, true, false), asList(asList(new CardExamplePosition(11, 7)), null, asList(new CardExamplePosition(0, 7)), null) ); } | public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test public void test_acceptsURL_rejectsNonDremioJdbcUrl() throws SQLException { assertThat( uut.acceptsURL("jdbc:notdremio:whatever"), equalTo( false ) ); } | @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void test_acceptsURL_rejectsNonDremioJdbc2() throws SQLException { assertThat( uut.acceptsURL("jdbc:optiq:"), equalTo( false ) ); } | @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void test_acceptsURL_rejectsNonJdbcUrl() throws SQLException { assertThat( uut.acceptsURL("dremio:"), equalTo( false ) ); } | @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } | Driver implements java.sql.Driver { @Override public boolean acceptsURL( String url ) throws SQLException { return impl.acceptsURL( url ); } Driver(); static boolean load(); @Override Connection connect( String url, Properties info ); @Override boolean acceptsURL( String url ); @Override DriverPropertyInfo[] getPropertyInfo( String url, Properties info ); @Override int getMajorVersion(); @Override int getMinorVersion(); @Override boolean jdbcCompliant(); @Override java.util.logging.Logger getParentLogger(); } |
@Test public void test_getByte_on_TINYINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) 127 ) ); assertThat( uut1.getByte( 0 ), equalTo( (byte) 127 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) -128 ) ); assertThat( uut2.getByte( 0 ), equalTo( (byte) -128 ) ); } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getByte_on_SMALLINT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) 127 ) ); assertThat( uut.getByte( 0 ), equalTo( (byte) 127 ) ); } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getByte_on_SMALLINT_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) 128 ) ); try { uut.getByte( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "128" ) ); assertThat( e.getMessage(), containsString( "getByte" ) ); assertThat( e.getMessage(), allOf( containsString( "short" ), containsString( "SMALLINT" ) ) ); throw e; } } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getByte_on_INTEGER_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new IntegerStubAccessor( -128 ) ); assertThat( uut.getByte( 0 ), equalTo( (byte) -128 ) ); } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getByte_on_INTEGER_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new IntegerStubAccessor( -129 ) ); try { uut.getByte( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "-129" ) ); assertThat( e.getMessage(), containsString( "getByte" ) ); assertThat( e.getMessage(), allOf( containsString( "int" ), containsString( "INTEGER" ) ) ); throw e; } } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getByte_on_BIGINT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( -128 ) ); assertThat( uut.getByte( 0 ), equalTo( (byte) -128 ) ); } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void startsWith() throws Exception { final File dataFile = temp.newFile("startsWithTest.json"); try (final PrintWriter printWriter = new PrintWriter(dataFile)) { printWriter.append("{ \"col\" : \"amazing restaurant. Very good food.\" }"); printWriter.append("{ \"col\" : \"This is a worst restaurant. bad food.\" }"); printWriter.append("{ \"col\" : \"Amazing environment. Amazing food.\" }"); printWriter.append("{ \"col\" : \"Not good.\" }"); } ReplacePatternRule rule = new ReplacePatternRule() .setSelectionType(ReplaceSelectionType.STARTS_WITH) .setSelectionPattern("amazing"); TransformRuleWrapper<ReplacePatternRule> ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'STARTS_WITH', 'amazing', false)", "CASE WHEN regexp_like(\"input.expr\", '^\\Qamazing\\E.*?') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '^\\Qamazing\\E.*?') THEN " + "regexp_replace(\"input.expr\", '^\\Qamazing\\E', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '^\\Qamazing\\E.*?') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '^\\Qamazing\\E.*?')" ); List<Object> outputSelReplace = list( (Object)"AMAZING restaurant. Very good food.", "This is a worst restaurant. bad food.", "Amazing environment. Amazing food.", "Not good." ); List<Object> outputCompleteReplace = list( (Object)"AMAZING", "This is a worst restaurant. bad food.", "Amazing environment. Amazing food.", "Not good." ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "AMAZING"}, outputSelReplace, asList(true, false, false, false), asList(asList(new CardExamplePosition(0, 7)), null, null, null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "AMAZING"}, outputCompleteReplace, asList(true, false, false, false), asList(asList(new CardExamplePosition(0, 7)), null, null, null) ); rule = rule.setIgnoreCase(true); ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'STARTS_WITH', 'amazing', true)", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u)^\\Qamazing\\E.*?') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u)^\\Qamazing\\E.*?') THEN " + "regexp_replace(\"input.expr\", '(?i)(?u)^\\Qamazing\\E', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u)^\\Qamazing\\E.*?') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '(?i)(?u)^\\Qamazing\\E.*?')" ); outputSelReplace = list( (Object)"AMAZING restaurant. Very good food.", "This is a worst restaurant. bad food.", "AMAZING environment. Amazing food.", "Not good." ); outputCompleteReplace = list( (Object)"AMAZING", "This is a worst restaurant. bad food.", "AMAZING", "Not good." ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "AMAZING"}, outputSelReplace, asList(true, false, true, false), asList(asList(new CardExamplePosition(0, 7)), null, asList(new CardExamplePosition(0, 7)), null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "AMAZING"}, outputCompleteReplace, asList(true, false, true, false), asList(asList(new CardExamplePosition(0, 7)), null, asList(new CardExamplePosition(0, 7)), null) ); } | public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getByte_on_BIGINT_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( 129 ) ); try { uut.getByte( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "129" ) ); assertThat( e.getMessage(), containsString( "getByte" ) ); assertThat( e.getMessage(), allOf( containsString( "long" ), containsString( "BIGINT" ) ) ); throw e; } } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getByte_on_FLOAT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( -128.0f ) ); assertThat( uut.getByte( 0 ), equalTo( (byte) -128 ) ); } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getByte_on_FLOAT_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( -130f ) ); try { uut.getByte( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "-130" ) ); assertThat( e.getMessage(), containsString( "getByte" ) ); assertThat( e.getMessage(), allOf( containsString( "float" ), anyOf( containsString( "REAL" ), containsString( "FLOAT" ) ) ) ); throw e; } } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getByte_on_DOUBLE_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 127.0d ) ); assertThat( uut.getByte( 0 ), equalTo( (byte) 127) ); } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getByte_on_DOUBLE_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( -130 ) ); try { uut.getByte( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "-130" ) ); assertThat( e.getMessage(), containsString( "getByte" ) ); assertThat( e.getMessage(), allOf( containsString( "double" ), anyOf( containsString( "DOUBLE PRECISION" ), containsString( "FLOAT(" ) ) ) ); throw e; } } | @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public byte getByte( int rowOffset ) throws InvalidAccessException { final byte result; switch ( getType().getMinorType() ) { case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = getByteValueOrThrow( innerAccessor.getShort( rowOffset ), "Java short / SQL SMALLINT" ); break; case INT: result = getByteValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getByteValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getByteValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getByteValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getByteValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getShort_on_TINYINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) 127 ) ); assertThat( uut1.getShort( 0 ), equalTo( (short) 127 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) -128 ) ); assertThat( uut2.getShort( 0 ), equalTo( (short) -128 ) ); } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getShort_on_SMALLINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) 32767 ) ); assertThat( uut1.getShort( 0 ), equalTo( (short) 32767 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) -32768 ) ); assertThat( uut2.getShort( 0 ), equalTo( (short) -32768 ) ); } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getShort_on_INTEGER_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new IntegerStubAccessor( 32767 ) ); assertThat( uut1.getShort( 0 ), equalTo( (short) 32767 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new IntegerStubAccessor( -32768 ) ); assertThat( uut2.getShort( 0 ), equalTo( (short) -32768 ) ); } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getShort_on_INTEGER_thatOverflows_throws() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new IntegerStubAccessor( -32769 ) ); try { uut.getShort( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "-32769" ) ); assertThat( e.getMessage(), containsString( "getShort" ) ); assertThat( e.getMessage(), allOf( containsString( "int" ), containsString( "INTEGER" ) ) ); throw e; } } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getShort_BIGINT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( -32678 ) ); assertThat( uut.getShort( 0 ), equalTo( (short) -32678 ) ); } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void endsWith() throws Exception { final File dataFile = temp.newFile("endsWithTest.json"); try (final PrintWriter printWriter = new PrintWriter(dataFile)) { printWriter.append("{ \"col\" : \"amazing restaurant. Very good food\" }"); printWriter.append("{ \"col\" : \"This is a worst restaurant. bad food\" }"); printWriter.append("{ \"col\" : \"Amazing environment. Amazing Food\" }"); printWriter.append("{ \"col\" : \"Not good\" }"); } ReplacePatternRule rule = new ReplacePatternRule() .setSelectionType(ReplaceSelectionType.ENDS_WITH) .setSelectionPattern("food"); TransformRuleWrapper<ReplacePatternRule> ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'ENDS_WITH', 'food', false)", "CASE WHEN regexp_like(\"input.expr\", '.*?\\Qfood\\E$') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '.*?\\Qfood\\E$') THEN " + "regexp_replace(\"input.expr\", '\\Qfood\\E$', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '.*?\\Qfood\\E$') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '.*?\\Qfood\\E$')" ); List<Object> outputSelReplace = list( (Object)"amazing restaurant. Very good dinner", "This is a worst restaurant. bad dinner", "Amazing environment. Amazing Food", "Not good" ); List<Object> outputCompleteReplace = list( (Object)"dinner", "dinner", "Amazing environment. Amazing Food", "Not good" ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "dinner"}, outputSelReplace, asList(true, true, false, false), asList(asList(new CardExamplePosition(30, 4)), asList(new CardExamplePosition(32, 4)), null, null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "dinner"}, outputCompleteReplace, asList(true, true, false, false), asList(asList(new CardExamplePosition(30, 4)), asList(new CardExamplePosition(32, 4)), null, null) ); rule = rule.setIgnoreCase(true); ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'ENDS_WITH', 'food', true)", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?\\Qfood\\E$') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?\\Qfood\\E$') THEN " + "regexp_replace(\"input.expr\", '(?i)(?u)\\Qfood\\E$', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?\\Qfood\\E$') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '(?i)(?u).*?\\Qfood\\E$')" ); outputSelReplace = list( (Object)"amazing restaurant. Very good dinner", "This is a worst restaurant. bad dinner", "Amazing environment. Amazing dinner", "Not good" ); outputCompleteReplace = list( (Object)"dinner", "dinner", "dinner", "Not good" ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "dinner"}, outputSelReplace, asList(true, true, true, false), asList(asList(new CardExamplePosition(30, 4)), asList(new CardExamplePosition(32, 4)), asList(new CardExamplePosition(29, 4)), null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "dinner"}, outputCompleteReplace, asList(true, true, true, false), asList(asList(new CardExamplePosition(30, 4)), asList(new CardExamplePosition(32, 4)), asList(new CardExamplePosition(29, 4)), null) ); } | public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getShort_on_BIGINT_thatOverflows_throws() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( 65535 ) ); try { uut.getShort( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "65535" ) ); assertThat( e.getMessage(), containsString( "getShort" ) ); assertThat( e.getMessage(), allOf( containsString( "long" ), containsString( "BIGINT" ) ) ); throw e; } } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getShort_on_FLOAT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( -32768f ) ); assertThat( uut.getShort( 0 ), equalTo( (short) -32768 ) ); } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getShort_on_FLOAT_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( -32769f ) ); try { uut.getShort( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "-32769" ) ); assertThat( e.getMessage(), containsString( "getShort" ) ); assertThat( e.getMessage(), allOf( containsString( "float" ), anyOf( containsString( "REAL" ), containsString( "FLOAT" ) ) ) ); throw e; } } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getShort_on_DOUBLE_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 32767d ) ); assertThat( uut.getShort( 0 ), equalTo( (short) 32767) ); } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getShort_on_DOUBLE_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 32768 ) ); try { uut.getShort( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "32768" ) ); assertThat( e.getMessage(), containsString( "getShort" ) ); assertThat( e.getMessage(), allOf( containsString( "double" ), anyOf( containsString( "DOUBLE PRECISION" ), containsString( "FLOAT" ) ) ) ); throw e; } } | @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public short getShort( int rowOffset ) throws InvalidAccessException { final short result; switch ( getType().getMinorType() ) { case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case INT: result = getShortValueOrThrow( innerAccessor.getInt( rowOffset ), "Java int / SQL INTEGER" ); break; case BIGINT: result = getShortValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getShortValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getShortValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getShortValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getByte( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getInt_on_TINYINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) 127 ) ); assertThat( uut1.getInt( 0 ), equalTo( 127 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) -128 ) ); assertThat( uut2.getInt( 0 ), equalTo( -128 ) ); } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getInt_on_SMALLINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) 32767 ) ); assertThat( uut1.getInt( 0 ), equalTo( 32767 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) -32768 ) ); assertThat( uut2.getInt( 0 ), equalTo( -32768 ) ); } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getInt_on_INTEGER_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new IntegerStubAccessor( 2147483647 ) ); assertThat( uut1.getInt( 0 ), equalTo( 2147483647 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new IntegerStubAccessor( -2147483648 ) ); assertThat( uut2.getInt( 0 ), equalTo( -2147483648 ) ); } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getInt_on_BIGINT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( 2147483647 ) ); assertThat( uut.getInt( 0 ), equalTo( 2147483647 ) ); } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getInt_on_BIGINT_thatOverflows_throws() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( 2147483648L ) ); try { uut.getInt( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "2147483648" ) ); assertThat( e.getMessage(), containsString( "getInt" ) ); assertThat( e.getMessage(), allOf( containsString( "long" ), containsString( "BIGINT" ) ) ); throw e; } } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void exact() throws Exception { final File dataFile = temp.newFile("exact.json"); try (final PrintWriter printWriter = new PrintWriter(dataFile)) { printWriter.append("{ \"col\" : \"Los Angeles\" }"); printWriter.append("{ \"col\" : \"LOS ANGELES\" }"); printWriter.append("{ \"col\" : \"LOS ANGELES, CA\" }"); printWriter.append("{ \"col\" : null }"); } ReplacePatternRule rule = new ReplacePatternRule() .setSelectionType(ReplaceSelectionType.EXACT) .setSelectionPattern("Los Angeles"); TransformRuleWrapper<ReplacePatternRule> ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'EXACT', 'Los Angeles', false)", "CASE WHEN \"input.expr\" = 'Los Angeles' THEN NULL ELSE \"input.expr\" END", "CASE WHEN \"input.expr\" = 'Los Angeles' THEN " + "'new''''value' ELSE \"input.expr\" END", "CASE WHEN \"input.expr\" = 'Los Angeles' THEN 'new value' ELSE \"input.expr\" END", "\"user\".\"col.with.dots\" = 'Los Angeles'" ); List<Object> outputSelReplace = list( (Object)"LOS ANGELES", "LOS ANGELES", "LOS ANGELES, CA", null ); List<Object> outputCompleteReplace = list( (Object)"LOS ANGELES", "LOS ANGELES", "LOS ANGELES, CA", null ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "LOS ANGELES"}, outputSelReplace, asList(true, false, false, false), asList(asList(new CardExamplePosition(0, 11)), null, null, null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "LOS ANGELES"}, outputCompleteReplace, asList(true, false, false, false), asList(asList(new CardExamplePosition(0, 11)), null, null, null) ); rule = rule.setIgnoreCase(true); ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'EXACT', 'Los Angeles', true)", "CASE WHEN lower(\"input.expr\") = lower('Los Angeles') THEN NULL ELSE \"input.expr\" END", "CASE WHEN lower(\"input.expr\") = lower('Los Angeles') THEN " + "'new''''value' ELSE \"input.expr\" END", "CASE WHEN lower(\"input.expr\") = lower('Los Angeles') THEN 'new value' ELSE \"input.expr\" END", "lower(\"user\".\"col.with.dots\") = lower('Los Angeles')" ); outputSelReplace = list( (Object)"LosAngeles", "LosAngeles", "LOS ANGELES, CA", null ); outputCompleteReplace = list( (Object)"LosAngeles", "LosAngeles", "LOS ANGELES, CA", null ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "LosAngeles"}, outputSelReplace, asList(true, true, false, false), asList(asList(new CardExamplePosition(0, 11)), asList(new CardExamplePosition(0, 11)), null, null) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "LosAngeles"}, outputCompleteReplace, asList(true, true, false, false), asList(asList(new CardExamplePosition(0, 11)), asList(new CardExamplePosition(0, 11)), null, null) ); } | public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test public void test_getInt_on_FLOAT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( 1e9f ) ); assertThat( uut.getInt( 0 ), equalTo( 1_000_000_000 ) ); } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getInt_on_FLOAT_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( 1e10f ) ); try { uut.getInt( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "1.0E10" ) ); assertThat( e.getMessage(), containsString( "getInt" ) ); assertThat( e.getMessage(), allOf( containsString( "float" ), anyOf( containsString( "REAL" ), containsString( "FLOAT" ) ) ) ); throw e; } } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getInt_on_DOUBLE_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( -2147483648.0d ) ); assertThat( uut.getInt( 0 ), equalTo( -2147483648 ) ); } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getInt_on_DOUBLE_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( -2147483649.0d ) ); try { uut.getInt( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "-2.147483649E9" ) ); assertThat( e.getMessage(), containsString( "getInt" ) ); assertThat( e.getMessage(), allOf( containsString( "double" ), containsString( "DOUBLE PRECISION" ) ) ); throw e; } } | @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public int getInt( int rowOffset ) throws InvalidAccessException { final int result; switch ( getType().getMinorType() ) { case INT: result = innerAccessor.getInt( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case BIGINT: result = getIntValueOrThrow( innerAccessor.getLong( rowOffset ), "Java long / SQL BIGINT" ); break; case FLOAT4: result = getIntValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getIntValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getIntValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getLong_on_TINYINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) 127 ) ); assertThat( uut1.getLong( 0 ), equalTo( 127L ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new TinyIntStubAccessor( (byte) -128 ) ); assertThat( uut2.getLong( 0 ), equalTo( -128L ) ); } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getLong_on_SMALLINT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) 32767 ) ); assertThat( uut1.getLong( 0 ), equalTo( 32767L ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new SmallIntStubAccessor( (short) -32768 ) ); assertThat( uut2.getLong( 0 ), equalTo( -32768L ) ); } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getLong_on_INTEGER_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new IntegerStubAccessor( 2147483647 ) ); assertThat( uut1.getLong( 0 ), equalTo( 2147483647L ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new IntegerStubAccessor( -2147483648 ) ); assertThat( uut2.getLong( 0 ), equalTo( -2147483648L ) ); } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getLong_on_BIGINT_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new BigIntStubAccessor( 2147483648L ) ); assertThat( uut.getLong( 0 ), equalTo( 2147483648L ) ); } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getLong_on_FLOAT_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( 9223372036854775807L * 1.0f ) ); assertThat( uut.getLong( 0 ), equalTo( 9223372036854775807L ) ); } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getLong_on_FLOAT_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new FloatStubAccessor( 1.5e20f ) ); try { uut.getLong( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "1.5000" ) ); assertThat( e.getMessage(), containsString( "getLong" ) ); assertThat( e.getMessage(), allOf( containsString( "float" ), anyOf( containsString( "REAL" ), containsString( "FLOAT" ) ) ) ); throw e; } } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void matches() throws Exception { final File dataFile = temp.newFile("matches.json"); try (final PrintWriter printWriter = new PrintWriter(dataFile)) { printWriter.append("{ \"col\" : \"Los Angeles\" }"); printWriter.append("{ \"col\" : \"LOS Angeles\" }"); printWriter.append("{ \"col\" : \"LOSANGELES\" }"); printWriter.append("{ \"col\" : \"LosAngeles, CA\" }"); } ReplacePatternRule rule = new ReplacePatternRule() .setSelectionType(ReplaceSelectionType.MATCHES) .setSelectionPattern("Los.*Angeles"); TransformRuleWrapper<ReplacePatternRule> ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'MATCHES', 'Los.*Angeles', false)", "CASE WHEN regexp_like(\"input.expr\", '.*?Los.*Angeles.*?') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '.*?Los.*Angeles.*?') THEN " + "regexp_replace(\"input.expr\", 'Los.*Angeles', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '.*?Los.*Angeles.*?') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '.*?Los.*Angeles.*?')" ); List<Object> outputSelReplace = list( (Object)"LOS ANGELES", "LOS Angeles", "LOSANGELES", "LOS ANGELES, CA" ); List<Object> outputCompleteReplace = list( (Object)"LOS ANGELES", "LOS Angeles", "LOSANGELES", "LOS ANGELES" ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "LOS ANGELES"}, outputSelReplace, asList(true, false, false, true), asList(asList(new CardExamplePosition(0, 11)), null, null, asList(new CardExamplePosition(0, 10))) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "LOS ANGELES"}, outputCompleteReplace, asList(true, false, false, true), asList(asList(new CardExamplePosition(0, 11)), null, null, asList(new CardExamplePosition(0, 10))) ); rule = rule.setIgnoreCase(true); ruleWrapper = recommender.wrapRule(rule); validateExpressions( ruleWrapper, "match_pattern_example(\"table.with.dots\".col, 'MATCHES', 'Los.*Angeles', true)", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?Los.*Angeles.*?') THEN NULL ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?Los.*Angeles.*?') THEN " + "regexp_replace(\"input.expr\", '(?i)(?u)Los.*Angeles', 'new''''value') ELSE \"input.expr\" END", "CASE WHEN regexp_like(\"input.expr\", '(?i)(?u).*?Los.*Angeles.*?') THEN 'new value' ELSE \"input.expr\" END", "regexp_like(\"user\".\"col.with.dots\", '(?i)(?u).*?Los.*Angeles.*?')" ); outputSelReplace = list( (Object)"LOS ANGELES", "LOS ANGELES", "LOS ANGELES", "LOS ANGELES, CA" ); outputCompleteReplace = list( (Object)"LOS ANGELES", "LOS ANGELES", "LOS ANGELES", "LOS ANGELES" ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "LOS ANGELES"}, outputSelReplace, asList(true, true, true, true), asList(asList(new CardExamplePosition(0, 11)), asList(new CardExamplePosition(0, 11)), asList(new CardExamplePosition(0, 10)), asList(new CardExamplePosition(0, 10))) ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "LOS ANGELES"}, outputCompleteReplace, asList(true, true, true, true), asList(asList(new CardExamplePosition(0, 11)), asList(new CardExamplePosition(0, 11)), asList(new CardExamplePosition(0, 10)), asList(new CardExamplePosition(0, 10))) ); } | public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test public void testIllegalUpgrade() throws Exception { thrown.expect(Exception.class); thrown.expectMessage("Illegal upgrade from OSS to EE"); final ByteString prevEdition = ByteString.copyFrom("OSS".getBytes()); final ConfigurationEntry configurationEntry = new ConfigurationEntry(); configurationEntry.setValue(prevEdition); final LegacyKVStoreProvider kvStoreProvider = LegacyKVStoreProviderAdapter.inMemory(CLASSPATH_SCAN_RESULT); kvStoreProvider.start(); final ConfigurationStore configurationStore = new ConfigurationStore(kvStoreProvider); configurationStore.put(SupportService.DREMIO_EDITION, configurationEntry); new Upgrade(DACConfig.newConfig(), CLASSPATH_SCAN_RESULT, false).validateUpgrade(kvStoreProvider, "EE"); } | @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); void run(); void run(boolean noDBOpenRetry); @VisibleForTesting void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition); void run(final LegacyKVStoreProvider storeProvider); static void main(String[] args); } | Upgrade { @VisibleForTesting public void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition) throws Exception { if (!getDACConfig().isMigrationEnabled()) { final ConfigurationStore configurationStore = new ConfigurationStore(storeProvider); final ConfigurationEntry entry = configurationStore.get(SupportService.DREMIO_EDITION); if (entry != null && entry.getValue() != null) { final String prevEdition = new String(entry.getValue().toByteArray()); if (!Strings.isNullOrEmpty(prevEdition) && !prevEdition.equals(curEdition)) { throw new Exception(String.format("Illegal upgrade from %s to %s", prevEdition, curEdition)); } } } } Upgrade(DACConfig dacConfig, ScanResult classPathScan, boolean verbose); void run(); void run(boolean noDBOpenRetry); @VisibleForTesting void validateUpgrade(final LegacyKVStoreProvider storeProvider, final String curEdition); void run(final LegacyKVStoreProvider storeProvider); static void main(String[] args); static final Comparator<Version> UPGRADE_VERSION_ORDERING; } |
@Test public void test_getLong_on_DOUBLE_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 9223372036854775807L * 1.0d ) ); assertThat( uut.getLong( 0 ), equalTo( 9223372036854775807L ) ); } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getLong_on_DOUBLE_thatOverflows_rejectsIt() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 1e20 ) ); try { uut.getLong( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "1.0E20" ) ); assertThat( e.getMessage(), containsString( "getLong" ) ); assertThat( e.getMessage(), allOf( containsString( "double" ), containsString( "DOUBLE PRECISION" ) ) ); throw e; } } | @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public long getLong( int rowOffset ) throws InvalidAccessException { final long result; switch ( getType().getMinorType() ) { case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case TINYINT: result = innerAccessor.getByte( rowOffset ); break; case SMALLINT: result = innerAccessor.getShort( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case FLOAT4: result = getLongValueOrThrow( innerAccessor.getFloat( rowOffset ), "Java float / SQL REAL/FLOAT" ); break; case FLOAT8: result = getLongValueOrThrow( innerAccessor.getDouble( rowOffset ), "Java double / SQL DOUBLE PRECISION" ); break; case DECIMAL: result = getLongValueOrThrow( innerAccessor.getBigDecimal( rowOffset ).doubleValue(), "Java decimal / SQL DECIMAL PRECISION" ); break; default: result = innerAccessor.getLong( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getFloat_on_FLOAT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new FloatStubAccessor( 1.23f ) ); assertThat( uut1.getFloat( 0 ), equalTo( 1.23f ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new FloatStubAccessor( Float.MAX_VALUE ) ); assertThat( uut2.getFloat( 0 ), equalTo( Float.MAX_VALUE ) ); final SqlAccessor uut3 = new TypeConvertingSqlAccessor( new FloatStubAccessor( Float.MIN_VALUE ) ); assertThat( uut3.getFloat( 0 ), equalTo( Float.MIN_VALUE ) ); } | @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getFloat_on_DOUBLE_thatFits_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 1.125 ) ); assertThat( uut1.getFloat( 0 ), equalTo( 1.125f ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new DoubleStubAccessor( Float.MAX_VALUE ) ); assertThat( uut2.getFloat( 0 ), equalTo( Float.MAX_VALUE ) ); } | @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test( expected = SQLConversionOverflowException.class ) public void test_getFloat_on_DOUBLE_thatOverflows_throws() throws InvalidAccessException { final SqlAccessor uut = new TypeConvertingSqlAccessor( new DoubleStubAccessor( 1e100 ) ); try { uut.getFloat( 0 ); } catch ( Throwable e ) { assertThat( e.getMessage(), containsString( "1.0E100" ) ); assertThat( e.getMessage(), containsString( "getFloat" ) ); assertThat( e.getMessage(), allOf( containsString( "double" ), anyOf ( containsString( "DOUBLE PRECISION" ), containsString( "FLOAT" ) ) ) ); throw e; } } | @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public float getFloat( int rowOffset ) throws InvalidAccessException { final float result; switch ( getType().getMinorType() ) { case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT8: final double value = innerAccessor.getDouble( rowOffset ); if ( Float.MIN_VALUE <= value && value <= Float.MAX_VALUE ) { result = (float) value; } else { throw newOverflowException( "getFloat(...)", "Java double / SQL DOUBLE PRECISION", value ); } break; case DECIMAL: final BigDecimal decimalValue = innerAccessor.getBigDecimal( rowOffset ); final float tempFloat = decimalValue.floatValue(); if ( Float.NEGATIVE_INFINITY == tempFloat || Float.POSITIVE_INFINITY == tempFloat) { throw newOverflowException( "getFloat(...)", "Java decimal / SQL DECIMAL PRECISION", tempFloat ); } else { result = tempFloat; } break; default: result = innerAccessor.getInt( rowOffset ); break; } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getDouble_on_FLOAT_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new FloatStubAccessor( 6.02e23f ) ); assertThat( uut1.getDouble( 0 ), equalTo( (double) 6.02e23f ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new FloatStubAccessor( Float.MAX_VALUE ) ); assertThat( uut2.getDouble( 0 ), equalTo( (double) Float.MAX_VALUE ) ); final SqlAccessor uut3 = new TypeConvertingSqlAccessor( new FloatStubAccessor( Float.MIN_VALUE ) ); assertThat( uut3.getDouble( 0 ), equalTo( (double) Float.MIN_VALUE ) ); } | @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void test_getDouble_on_DOUBLE_getsIt() throws InvalidAccessException { final SqlAccessor uut1 = new TypeConvertingSqlAccessor( new DoubleStubAccessor( -1e100 ) ); assertThat( uut1.getDouble( 0 ), equalTo( -1e100 ) ); final SqlAccessor uut2 = new TypeConvertingSqlAccessor( new DoubleStubAccessor( Double.MAX_VALUE ) ); assertThat( uut2.getDouble( 0 ), equalTo( Double.MAX_VALUE ) ); final SqlAccessor uut3 = new TypeConvertingSqlAccessor( new DoubleStubAccessor( Double.MIN_VALUE ) ); assertThat( uut3.getDouble( 0 ), equalTo( Double.MIN_VALUE ) ); } | @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } | TypeConvertingSqlAccessor implements SqlAccessor { @Override public double getDouble( int rowOffset ) throws InvalidAccessException { final double result; switch ( getType().getMinorType() ) { case FLOAT8: result = innerAccessor.getDouble( rowOffset ); break; case INT: result = innerAccessor.getInt( rowOffset ); break; case BIGINT: result = innerAccessor.getLong( rowOffset ); break; case FLOAT4: result = innerAccessor.getFloat( rowOffset ); break; case DECIMAL: result = innerAccessor.getBigDecimal( rowOffset ).doubleValue(); break; default: result = innerAccessor.getLong( rowOffset ); } return result; } TypeConvertingSqlAccessor( SqlAccessor innerAccessor ); @Override MajorType getType(); @Override Class<?> getObjectClass(); @Override boolean isNull( int rowOffset ); @Override byte getByte( int rowOffset ); @Override short getShort( int rowOffset ); @Override int getInt( int rowOffset ); @Override long getLong( int rowOffset ); @Override float getFloat( int rowOffset ); @Override double getDouble( int rowOffset ); @Override BigDecimal getBigDecimal( int rowOffset ); @Override boolean getBoolean( int rowOffset ); @Override String getString( int rowOffset ); @Override byte[] getBytes( int rowOffset ); @Override Date getDate( int rowOffset, Calendar calendar ); @Override Time getTime( int rowOffset, Calendar calendar ); @Override Timestamp getTimestamp( int rowOffset, Calendar calendar ); @Override Object getObject( int rowOffset ); @Override char getChar( int rowOffset ); @Override InputStream getStream( int rowOffset ); @Override Reader getReader( int rowOffset ); } |
@Test public void testEmpty() { DictionaryBuilder<String> builder = new DictionaryBuilder<>(String.class); Iterator<String> iterator = builder.build().iterator(); assertFalse(iterator.hasNext()); } | public Iterable<T> build() { Preconditions.checkArgument(!isBuilt, "build can only be called once"); isBuilt = true; if (valueAccumulator.isEmpty()) { return Collections.emptyList(); } final T[] values = ObjectArrays.newArray(clazzType, valueAccumulator.size()); for (ObjectIntCursor<T> entry : valueAccumulator) { values[entry.value] = entry.key; } return Arrays.asList(values); } | DictionaryBuilder { public Iterable<T> build() { Preconditions.checkArgument(!isBuilt, "build can only be called once"); isBuilt = true; if (valueAccumulator.isEmpty()) { return Collections.emptyList(); } final T[] values = ObjectArrays.newArray(clazzType, valueAccumulator.size()); for (ObjectIntCursor<T> entry : valueAccumulator) { values[entry.value] = entry.key; } return Arrays.asList(values); } } | DictionaryBuilder { public Iterable<T> build() { Preconditions.checkArgument(!isBuilt, "build can only be called once"); isBuilt = true; if (valueAccumulator.isEmpty()) { return Collections.emptyList(); } final T[] values = ObjectArrays.newArray(clazzType, valueAccumulator.size()); for (ObjectIntCursor<T> entry : valueAccumulator) { values[entry.value] = entry.key; } return Arrays.asList(values); } DictionaryBuilder(final Class<T> clazzType); } | DictionaryBuilder { public Iterable<T> build() { Preconditions.checkArgument(!isBuilt, "build can only be called once"); isBuilt = true; if (valueAccumulator.isEmpty()) { return Collections.emptyList(); } final T[] values = ObjectArrays.newArray(clazzType, valueAccumulator.size()); for (ObjectIntCursor<T> entry : valueAccumulator) { values[entry.value] = entry.key; } return Arrays.asList(values); } DictionaryBuilder(final Class<T> clazzType); int getOrCreateSubscript(final T value); Iterable<T> build(); } | DictionaryBuilder { public Iterable<T> build() { Preconditions.checkArgument(!isBuilt, "build can only be called once"); isBuilt = true; if (valueAccumulator.isEmpty()) { return Collections.emptyList(); } final T[] values = ObjectArrays.newArray(clazzType, valueAccumulator.size()); for (ObjectIntCursor<T> entry : valueAccumulator) { values[entry.value] = entry.key; } return Arrays.asList(values); } DictionaryBuilder(final Class<T> clazzType); int getOrCreateSubscript(final T value); Iterable<T> build(); } |
@Test public void buildInputFormatLookup() { { assertTrue(HiveReaderProtoUtil.buildInputFormatLookup(HiveTableXattr.newBuilder().build()).size() == 0); } { HiveTableXattr xattr = HiveTableXattr.newBuilder() .addAllPartitionXattrs( Lists.newArrayList( newPartitionXattrWithInputFormat("a"), newPartitionXattrWithInputFormat("a"), newPartitionXattrWithInputFormat("b"))) .build(); Map<String, Integer> result = HiveReaderProtoUtil.buildInputFormatLookup(xattr); assertTrue(result.size() == 2); assertNotNull(result.get("a")); assertNotNull(result.get("b")); } { HiveTableXattr xattr = HiveTableXattr.newBuilder() .addAllPartitionXattrs( Lists.newArrayList( newPartitionXattrWithInputFormat("a"), newPartitionXattrWithInputFormat("b"))) .setInputFormat("c") .build(); Map<String, Integer> result = HiveReaderProtoUtil.buildInputFormatLookup(xattr); assertTrue(result.size() == 3); assertNotNull(result.get("a")); assertNotNull(result.get("b")); assertNotNull(result.get("c")); } { HiveTableXattr xattr = HiveTableXattr.newBuilder() .addAllPartitionXattrs( Lists.newArrayList( newPartitionXattrWithInputFormat("a"), newPartitionXattrWithInputFormat("b"))) .setInputFormat("a") .build(); Map<String, Integer> result = HiveReaderProtoUtil.buildInputFormatLookup(xattr); assertTrue(result.size() == 2); assertNotNull(result.get("a")); assertNotNull(result.get("b")); } } | @Deprecated static Map<String, Integer> buildInputFormatLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<String, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { if (partitionXattr.hasInputFormat() && !lookup.containsKey(partitionXattr.getInputFormat())) { lookup.put(partitionXattr.getInputFormat(), i++); } } if (tableXattr.hasInputFormat() && !lookup.containsKey(tableXattr.getInputFormat())) { lookup.put(tableXattr.getInputFormat(), i); } return lookup; } | HiveReaderProtoUtil { @Deprecated static Map<String, Integer> buildInputFormatLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<String, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { if (partitionXattr.hasInputFormat() && !lookup.containsKey(partitionXattr.getInputFormat())) { lookup.put(partitionXattr.getInputFormat(), i++); } } if (tableXattr.hasInputFormat() && !lookup.containsKey(tableXattr.getInputFormat())) { lookup.put(tableXattr.getInputFormat(), i); } return lookup; } } | HiveReaderProtoUtil { @Deprecated static Map<String, Integer> buildInputFormatLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<String, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { if (partitionXattr.hasInputFormat() && !lookup.containsKey(partitionXattr.getInputFormat())) { lookup.put(partitionXattr.getInputFormat(), i++); } } if (tableXattr.hasInputFormat() && !lookup.containsKey(tableXattr.getInputFormat())) { lookup.put(tableXattr.getInputFormat(), i); } return lookup; } private HiveReaderProtoUtil(); } | HiveReaderProtoUtil { @Deprecated static Map<String, Integer> buildInputFormatLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<String, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { if (partitionXattr.hasInputFormat() && !lookup.containsKey(partitionXattr.getInputFormat())) { lookup.put(partitionXattr.getInputFormat(), i++); } } if (tableXattr.hasInputFormat() && !lookup.containsKey(tableXattr.getInputFormat())) { lookup.put(tableXattr.getInputFormat(), i); } return lookup; } private HiveReaderProtoUtil(); @Deprecated static void encodePropertiesAsDictionary(HiveTableXattr.Builder tableXattr); static List<Prop> getTableProperties(final HiveTableXattr tableXattr); static Optional<String> getTableInputFormat(final HiveTableXattr tableXattr); static Optional<String> getTableStorageHandler(final HiveTableXattr tableXattr); static Optional<String> getTableSerializationLib(final HiveTableXattr tableXattr); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, int partitionIndex); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionSerializationLib(final HiveTableXattr tableXattr, int partitionId); static String getPartitionSerializationLib(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static PartitionXattr getPartitionXattr(SplitAndPartitionInfo split); static boolean isPreDremioVersion3dot2dot0LegacyFormat(final HiveTableXattr tableXattr); static Map<String, AttributeValue> convertValuesToNonProtoAttributeValues(Map<String, HiveReaderProto.AttributeValue> protoMap); static HiveReaderProto.AttributeValue toProtobuf(AttributeValue attributeValue); static AttributeValue toAttribute(HiveReaderProto.AttributeValue attributeValueProto); static String getTypeName(AttributeValue value); static boolean getBoolean(AttributeValue attributeValue); } | HiveReaderProtoUtil { @Deprecated static Map<String, Integer> buildInputFormatLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<String, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { if (partitionXattr.hasInputFormat() && !lookup.containsKey(partitionXattr.getInputFormat())) { lookup.put(partitionXattr.getInputFormat(), i++); } } if (tableXattr.hasInputFormat() && !lookup.containsKey(tableXattr.getInputFormat())) { lookup.put(tableXattr.getInputFormat(), i); } return lookup; } private HiveReaderProtoUtil(); @Deprecated static void encodePropertiesAsDictionary(HiveTableXattr.Builder tableXattr); static List<Prop> getTableProperties(final HiveTableXattr tableXattr); static Optional<String> getTableInputFormat(final HiveTableXattr tableXattr); static Optional<String> getTableStorageHandler(final HiveTableXattr tableXattr); static Optional<String> getTableSerializationLib(final HiveTableXattr tableXattr); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, int partitionIndex); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionSerializationLib(final HiveTableXattr tableXattr, int partitionId); static String getPartitionSerializationLib(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static PartitionXattr getPartitionXattr(SplitAndPartitionInfo split); static boolean isPreDremioVersion3dot2dot0LegacyFormat(final HiveTableXattr tableXattr); static Map<String, AttributeValue> convertValuesToNonProtoAttributeValues(Map<String, HiveReaderProto.AttributeValue> protoMap); static HiveReaderProto.AttributeValue toProtobuf(AttributeValue attributeValue); static AttributeValue toAttribute(HiveReaderProto.AttributeValue attributeValueProto); static String getTypeName(AttributeValue value); static boolean getBoolean(AttributeValue attributeValue); } |
@Test public void buildPropLookup() { { assertTrue(HiveReaderProtoUtil.buildPropLookup(HiveTableXattr.newBuilder().build()).size() == 0); } { HiveTableXattr.Builder xattr = HiveTableXattr.newBuilder() .addAllPartitionXattrs( Lists.newArrayList( newPartitionXattrWithProps(newProp("a", "b")), newPartitionXattrWithProps(newProp("c", "d"), newProp("a", "b")))); Map<Prop, Integer> lookup = HiveReaderProtoUtil.buildPropLookup(xattr); assertTrue(lookup.size() == 2); assertNotNull(lookup.get(newProp("a", "b"))); assertNotNull(lookup.get(newProp("c", "d"))); } { HiveTableXattr.Builder xattr = HiveTableXattr.newBuilder() .addAllPartitionXattrs( Lists.newArrayList( newPartitionXattrWithProps(newProp("a", "b"), newProp("c", "d")))) .addAllTableProperty( Lists.newArrayList( newProp("a", "c"))); Map<Prop, Integer> lookup = HiveReaderProtoUtil.buildPropLookup(xattr); assertTrue(lookup.size() == 3); assertNotNull(lookup.get(newProp("a", "b"))); assertNotNull(lookup.get(newProp("c", "d"))); assertNotNull(lookup.get(newProp("a", "c"))); } { HiveTableXattr.Builder xattr = HiveTableXattr.newBuilder() .addAllPartitionXattrs( Lists.newArrayList( newPartitionXattrWithProps(newProp("a", "b"), newProp("c", "d")), newPartitionXattrWithProps(newProp("c", "d"), newProp("c", "d")), newPartitionXattrWithProps(newProp("c", "d"), newProp("c", "e")), newPartitionXattrWithProps(newProp("c", "d")), newPartitionXattrWithProps(newProp("c", "d")), newPartitionXattrWithProps(newProp("c", "d")))) .addAllTableProperty( Lists.newArrayList( newProp("a", "b"), newProp("a", "b"), newProp("a", "b"), newProp("a", "b"), newProp("a", "c"))); Map<Prop, Integer> lookup = HiveReaderProtoUtil.buildPropLookup(xattr); assertTrue(lookup.size() == 4); assertNotNull(lookup.get(newProp("a", "b"))); assertNotNull(lookup.get(newProp("c", "d"))); assertNotNull(lookup.get(newProp("a", "c"))); assertNotNull(lookup.get(newProp("c", "e"))); } } | @Deprecated static Map<Prop, Integer> buildPropLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<Prop, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { for (final Prop prop : partitionXattr.getPartitionPropertyList()) { if (!lookup.containsKey(prop)) { lookup.put(prop, i++); } } } for (final Prop tableProp : tableXattr.getTablePropertyList()) { if (!lookup.containsKey(tableProp)) { lookup.put(tableProp, i++); } } return lookup; } | HiveReaderProtoUtil { @Deprecated static Map<Prop, Integer> buildPropLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<Prop, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { for (final Prop prop : partitionXattr.getPartitionPropertyList()) { if (!lookup.containsKey(prop)) { lookup.put(prop, i++); } } } for (final Prop tableProp : tableXattr.getTablePropertyList()) { if (!lookup.containsKey(tableProp)) { lookup.put(tableProp, i++); } } return lookup; } } | HiveReaderProtoUtil { @Deprecated static Map<Prop, Integer> buildPropLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<Prop, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { for (final Prop prop : partitionXattr.getPartitionPropertyList()) { if (!lookup.containsKey(prop)) { lookup.put(prop, i++); } } } for (final Prop tableProp : tableXattr.getTablePropertyList()) { if (!lookup.containsKey(tableProp)) { lookup.put(tableProp, i++); } } return lookup; } private HiveReaderProtoUtil(); } | HiveReaderProtoUtil { @Deprecated static Map<Prop, Integer> buildPropLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<Prop, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { for (final Prop prop : partitionXattr.getPartitionPropertyList()) { if (!lookup.containsKey(prop)) { lookup.put(prop, i++); } } } for (final Prop tableProp : tableXattr.getTablePropertyList()) { if (!lookup.containsKey(tableProp)) { lookup.put(tableProp, i++); } } return lookup; } private HiveReaderProtoUtil(); @Deprecated static void encodePropertiesAsDictionary(HiveTableXattr.Builder tableXattr); static List<Prop> getTableProperties(final HiveTableXattr tableXattr); static Optional<String> getTableInputFormat(final HiveTableXattr tableXattr); static Optional<String> getTableStorageHandler(final HiveTableXattr tableXattr); static Optional<String> getTableSerializationLib(final HiveTableXattr tableXattr); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, int partitionIndex); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionSerializationLib(final HiveTableXattr tableXattr, int partitionId); static String getPartitionSerializationLib(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static PartitionXattr getPartitionXattr(SplitAndPartitionInfo split); static boolean isPreDremioVersion3dot2dot0LegacyFormat(final HiveTableXattr tableXattr); static Map<String, AttributeValue> convertValuesToNonProtoAttributeValues(Map<String, HiveReaderProto.AttributeValue> protoMap); static HiveReaderProto.AttributeValue toProtobuf(AttributeValue attributeValue); static AttributeValue toAttribute(HiveReaderProto.AttributeValue attributeValueProto); static String getTypeName(AttributeValue value); static boolean getBoolean(AttributeValue attributeValue); } | HiveReaderProtoUtil { @Deprecated static Map<Prop, Integer> buildPropLookup(HiveTableXattrOrBuilder tableXattr) { int i = 0; final Map<Prop, Integer> lookup = Maps.newHashMap(); for (final PartitionXattr partitionXattr : tableXattr.getPartitionXattrsList()) { for (final Prop prop : partitionXattr.getPartitionPropertyList()) { if (!lookup.containsKey(prop)) { lookup.put(prop, i++); } } } for (final Prop tableProp : tableXattr.getTablePropertyList()) { if (!lookup.containsKey(tableProp)) { lookup.put(tableProp, i++); } } return lookup; } private HiveReaderProtoUtil(); @Deprecated static void encodePropertiesAsDictionary(HiveTableXattr.Builder tableXattr); static List<Prop> getTableProperties(final HiveTableXattr tableXattr); static Optional<String> getTableInputFormat(final HiveTableXattr tableXattr); static Optional<String> getTableStorageHandler(final HiveTableXattr tableXattr); static Optional<String> getTableSerializationLib(final HiveTableXattr tableXattr); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, int partitionIndex); static List<Prop> getPartitionProperties(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionInputFormat(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, int partitionId); static Optional<String> getPartitionStorageHandler(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static Optional<String> getPartitionSerializationLib(final HiveTableXattr tableXattr, int partitionId); static String getPartitionSerializationLib(final HiveTableXattr tableXattr, final PartitionXattr partitionXattr); static PartitionXattr getPartitionXattr(SplitAndPartitionInfo split); static boolean isPreDremioVersion3dot2dot0LegacyFormat(final HiveTableXattr tableXattr); static Map<String, AttributeValue> convertValuesToNonProtoAttributeValues(Map<String, HiveReaderProto.AttributeValue> protoMap); static HiveReaderProto.AttributeValue toProtobuf(AttributeValue attributeValue); static AttributeValue toAttribute(HiveReaderProto.AttributeValue attributeValueProto); static String getTypeName(AttributeValue value); static boolean getBoolean(AttributeValue attributeValue); } |
@Test public void isNull() throws Exception { final File dataFile = temp.newFile("nullTest.json"); try (final PrintWriter printWriter = new PrintWriter(dataFile)) { printWriter.append("{ \"col\" : \"Los Angeles\" }"); printWriter.append("{ \"col\" : null }"); } ReplacePatternRule rule = new ReplacePatternRule() .setSelectionType(ReplaceSelectionType.IS_NULL); TransformRuleWrapper<ReplacePatternRule> ruleWrapper = recommender.wrapRule(rule); assertEquals("CASE WHEN \"input.expr\" IS NULL THEN 'new''''value' ELSE \"input.expr\" END", ruleWrapper.getFunctionExpr("\"input.expr\"", ReplaceType.SELECTION, "new''value")); assertEquals("CASE WHEN \"input.expr\" IS NULL THEN 'new value' ELSE \"input.expr\" END", ruleWrapper.getFunctionExpr("\"input.expr\"", ReplaceType.VALUE, "new value")); assertEquals("\"user\".\"col.with.dots\" IS NULL", ruleWrapper.getMatchFunctionExpr("\"user\".\"col.with.dots\"")); List<Object> output = list( (Object)"Los Angeles", "Los Angeles" ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.SELECTION, "Los Angeles"}, output, asList(false, true), null ); validate(dataFile.getAbsolutePath(), ruleWrapper, new Object[] { ReplaceType.VALUE, "Los Angeles"}, output, asList(false, true), null ); } | public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } | ReplaceRecommender extends Recommender<ReplacePatternRule, Selection> { public TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule) { return new ReplaceTransformRuleWrapper(rule); } @Override List<ReplacePatternRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<ReplacePatternRule> wrapRule(ReplacePatternRule rule); static ReplaceMatcher getMatcher(ReplacePatternRule rule); } |
@Test public void testAzureOauthCopy() { DremioFileSystem fileSystem = new DremioFileSystem(); Configuration conf = new Configuration(); conf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, ENDPOINT); conf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, CLIEN_ID); conf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, PASSWORD); fileSystem.updateOAuthConfig(conf, "testAccount.1234", "testAccount"); Assert.assertEquals(ENDPOINT, conf.get("dremio.azure.tokenEndpoint")); Assert.assertEquals(CLIEN_ID, conf.get("dremio.azure.clientId")); Assert.assertEquals(PASSWORD, conf.get("dremio.azure.clientSecret")); } | void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path path, int i); @Override FSDataOutputStream create(Path path, FsPermission fsPermission, boolean overwrite, int i, short i1, long l, Progressable progressable); @Override FSDataOutputStream append(Path path, int i, Progressable progressable); @Override boolean rename(Path path, Path path1); @Override boolean delete(Path path, boolean recursive); @Override FileStatus[] listStatus(Path path); @Override void setWorkingDirectory(Path path); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path path, FsPermission fsPermission); @Override FileStatus getFileStatus(Path path); boolean supportsAsync(); AsyncByteReader getAsyncByteReader(AsyncByteReader.FileKey fileKey, OperatorStats operatorStats); @Override String getScheme(); } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path path, int i); @Override FSDataOutputStream create(Path path, FsPermission fsPermission, boolean overwrite, int i, short i1, long l, Progressable progressable); @Override FSDataOutputStream append(Path path, int i, Progressable progressable); @Override boolean rename(Path path, Path path1); @Override boolean delete(Path path, boolean recursive); @Override FileStatus[] listStatus(Path path); @Override void setWorkingDirectory(Path path); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path path, FsPermission fsPermission); @Override FileStatus getFileStatus(Path path); boolean supportsAsync(); AsyncByteReader getAsyncByteReader(AsyncByteReader.FileKey fileKey, OperatorStats operatorStats); @Override String getScheme(); } |
@Test public void testAzureOauthCopyWithAccountProperties() { DremioFileSystem fileSystem = new DremioFileSystem(); Configuration conf = new Configuration(); conf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT + ".testAccount", ENDPOINT); conf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID + ".testAccount", CLIEN_ID); conf.set(FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET + ".testAccount", PASSWORD); fileSystem.updateOAuthConfig(conf, "testAccount.1234", "testAccount"); Assert.assertEquals(ENDPOINT, conf.get("dremio.azure.tokenEndpoint")); Assert.assertEquals(CLIEN_ID, conf.get("dremio.azure.clientId")); Assert.assertEquals(PASSWORD, conf.get("dremio.azure.clientSecret")); } | void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path path, int i); @Override FSDataOutputStream create(Path path, FsPermission fsPermission, boolean overwrite, int i, short i1, long l, Progressable progressable); @Override FSDataOutputStream append(Path path, int i, Progressable progressable); @Override boolean rename(Path path, Path path1); @Override boolean delete(Path path, boolean recursive); @Override FileStatus[] listStatus(Path path); @Override void setWorkingDirectory(Path path); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path path, FsPermission fsPermission); @Override FileStatus getFileStatus(Path path); boolean supportsAsync(); AsyncByteReader getAsyncByteReader(AsyncByteReader.FileKey fileKey, OperatorStats operatorStats); @Override String getScheme(); } | DremioFileSystem extends FileSystem { void updateOAuthConfig(Configuration conf, String accountName, String accountNameWithoutSuffix) { final String CLIENT_ID = "dremio.azure.clientId"; final String TOKEN_ENDPOINT = "dremio.azure.tokenEndpoint"; final String CLIENT_SECRET = "dremio.azure.clientSecret"; String refreshToken = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ENDPOINT, accountName, accountNameWithoutSuffix, "OAuth Client Endpoint not found."); String clientId = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_ID, accountName, accountNameWithoutSuffix, "OAuth Client Id not found."); String password = getValueForProperty(conf, FS_AZURE_ACCOUNT_OAUTH_CLIENT_SECRET, accountName, accountNameWithoutSuffix ,"OAuth Client Password not found."); conf.set(CLIENT_ID, clientId); conf.set(TOKEN_ENDPOINT, refreshToken); conf.set(CLIENT_SECRET, password); } @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path path, int i); @Override FSDataOutputStream create(Path path, FsPermission fsPermission, boolean overwrite, int i, short i1, long l, Progressable progressable); @Override FSDataOutputStream append(Path path, int i, Progressable progressable); @Override boolean rename(Path path, Path path1); @Override boolean delete(Path path, boolean recursive); @Override FileStatus[] listStatus(Path path); @Override void setWorkingDirectory(Path path); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path path, FsPermission fsPermission); @Override FileStatus getFileStatus(Path path); boolean supportsAsync(); AsyncByteReader getAsyncByteReader(AsyncByteReader.FileKey fileKey, OperatorStats operatorStats); @Override String getScheme(); } |
@Test public void ensureStoragePluginIsUsedForUsername() throws Exception { final String originalName = "Test"; final String finalName = "Replaced"; final HiveScanBatchCreator creator = new HiveScanBatchCreator(); final HiveStoragePlugin plugin = mock(HiveStoragePlugin.class); when(plugin.getUsername(originalName)).thenReturn(finalName); final FragmentExecutionContext fragmentExecutionContext = mock(FragmentExecutionContext.class); when(fragmentExecutionContext.getStoragePlugin(any())).thenReturn(plugin); final OpProps props = mock(OpProps.class); final HiveProxyingSubScan hiveSubScan = mock(HiveProxyingSubScan.class); when(hiveSubScan.getProps()).thenReturn(props); when(hiveSubScan.getProps().getUserName()).thenReturn(originalName); final UserGroupInformation ugi = creator.getUGI(plugin, hiveSubScan); verify(plugin).getUsername(originalName); assertEquals(finalName, ugi.getUserName()); } | @VisibleForTesting public UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } @Override ProducerOperator create(FragmentExecutionContext fragmentExecContext, OperatorContext context, HiveProxyingSubScan config); @VisibleForTesting UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config); } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { @VisibleForTesting public UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config) { final String userName = storagePlugin.getUsername(config.getProps().getUserName()); return HiveImpersonationUtil.createProxyUgi(userName); } @Override ProducerOperator create(FragmentExecutionContext fragmentExecContext, OperatorContext context, HiveProxyingSubScan config); @VisibleForTesting UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config); } |
@Test public void testAllSplitsAreOnS3() { List<SplitAndPartitionInfo> s3Splits = buildSplits("s3"); List<SplitAndPartitionInfo> hdfsplits = buildSplits("hdfs"); HiveScanBatchCreator scanBatchCreator = new HiveScanBatchCreator(); assertTrue(scanBatchCreator.allSplitsAreOnS3(s3Splits)); assertFalse(scanBatchCreator.allSplitsAreOnS3(hdfsplits)); } | boolean allSplitsAreOnS3(List<SplitAndPartitionInfo> splits) { for (SplitAndPartitionInfo split : splits) { try { final HiveReaderProto.HiveSplitXattr splitAttr = HiveReaderProto.HiveSplitXattr.parseFrom(split.getDatasetSplitInfo().getExtendedProperty()); final FileSplit fullFileSplit = (FileSplit) HiveUtilities.deserializeInputSplit(splitAttr.getInputSplit()); if (!AsyncReaderUtils.S3_FILE_SYSTEM.contains(fullFileSplit.getPath().toUri().getScheme().toLowerCase())) { logger.error("Data file {} is not on S3.", fullFileSplit.getPath()); return false; } } catch (IOException | ReflectiveOperationException e) { throw new RuntimeException("Failed to parse dataset split for " + split.getPartitionInfo().getSplitKey(), e); } } return true; } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { boolean allSplitsAreOnS3(List<SplitAndPartitionInfo> splits) { for (SplitAndPartitionInfo split : splits) { try { final HiveReaderProto.HiveSplitXattr splitAttr = HiveReaderProto.HiveSplitXattr.parseFrom(split.getDatasetSplitInfo().getExtendedProperty()); final FileSplit fullFileSplit = (FileSplit) HiveUtilities.deserializeInputSplit(splitAttr.getInputSplit()); if (!AsyncReaderUtils.S3_FILE_SYSTEM.contains(fullFileSplit.getPath().toUri().getScheme().toLowerCase())) { logger.error("Data file {} is not on S3.", fullFileSplit.getPath()); return false; } } catch (IOException | ReflectiveOperationException e) { throw new RuntimeException("Failed to parse dataset split for " + split.getPartitionInfo().getSplitKey(), e); } } return true; } } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { boolean allSplitsAreOnS3(List<SplitAndPartitionInfo> splits) { for (SplitAndPartitionInfo split : splits) { try { final HiveReaderProto.HiveSplitXattr splitAttr = HiveReaderProto.HiveSplitXattr.parseFrom(split.getDatasetSplitInfo().getExtendedProperty()); final FileSplit fullFileSplit = (FileSplit) HiveUtilities.deserializeInputSplit(splitAttr.getInputSplit()); if (!AsyncReaderUtils.S3_FILE_SYSTEM.contains(fullFileSplit.getPath().toUri().getScheme().toLowerCase())) { logger.error("Data file {} is not on S3.", fullFileSplit.getPath()); return false; } } catch (IOException | ReflectiveOperationException e) { throw new RuntimeException("Failed to parse dataset split for " + split.getPartitionInfo().getSplitKey(), e); } } return true; } } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { boolean allSplitsAreOnS3(List<SplitAndPartitionInfo> splits) { for (SplitAndPartitionInfo split : splits) { try { final HiveReaderProto.HiveSplitXattr splitAttr = HiveReaderProto.HiveSplitXattr.parseFrom(split.getDatasetSplitInfo().getExtendedProperty()); final FileSplit fullFileSplit = (FileSplit) HiveUtilities.deserializeInputSplit(splitAttr.getInputSplit()); if (!AsyncReaderUtils.S3_FILE_SYSTEM.contains(fullFileSplit.getPath().toUri().getScheme().toLowerCase())) { logger.error("Data file {} is not on S3.", fullFileSplit.getPath()); return false; } } catch (IOException | ReflectiveOperationException e) { throw new RuntimeException("Failed to parse dataset split for " + split.getPartitionInfo().getSplitKey(), e); } } return true; } @Override ProducerOperator create(FragmentExecutionContext fragmentExecContext, OperatorContext context, HiveProxyingSubScan config); @VisibleForTesting UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config); } | HiveScanBatchCreator implements HiveProxiedScanBatchCreator { boolean allSplitsAreOnS3(List<SplitAndPartitionInfo> splits) { for (SplitAndPartitionInfo split : splits) { try { final HiveReaderProto.HiveSplitXattr splitAttr = HiveReaderProto.HiveSplitXattr.parseFrom(split.getDatasetSplitInfo().getExtendedProperty()); final FileSplit fullFileSplit = (FileSplit) HiveUtilities.deserializeInputSplit(splitAttr.getInputSplit()); if (!AsyncReaderUtils.S3_FILE_SYSTEM.contains(fullFileSplit.getPath().toUri().getScheme().toLowerCase())) { logger.error("Data file {} is not on S3.", fullFileSplit.getPath()); return false; } } catch (IOException | ReflectiveOperationException e) { throw new RuntimeException("Failed to parse dataset split for " + split.getPartitionInfo().getSplitKey(), e); } } return true; } @Override ProducerOperator create(FragmentExecutionContext fragmentExecContext, OperatorContext context, HiveProxyingSubScan config); @VisibleForTesting UserGroupInformation getUGI(HiveStoragePlugin storagePlugin, HiveProxyingSubScan config); } |
@Test public void impersonationDisabledShouldReturnSystemUser() { final HiveConf hiveConf = new HiveConf(); hiveConf.setBoolVar(HIVE_SERVER2_ENABLE_DOAS, false); final SabotContext context = mock(SabotContext.class); final HiveStoragePlugin plugin = createHiveStoragePlugin(hiveConf, context); final String userName = plugin.getUsername(TEST_USER_NAME); assertEquals(SystemUser.SYSTEM_USERNAME, userName); } | public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting HiveStoragePlugin(HiveConf hiveConf, SabotContext context, String name); HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting HiveStoragePlugin(HiveConf hiveConf, SabotContext context, String name); HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(final DatasetHandle datasetHandle, final DatasetMetadata oldDatasetMetadata,
final Map<String, AttributeValue> attributes, final AlterMetadataOption... options); T getPF4JStoragePlugin(); } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting HiveStoragePlugin(HiveConf hiveConf, SabotContext context, String name); HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(final DatasetHandle datasetHandle, final DatasetMetadata oldDatasetMetadata,
final Map<String, AttributeValue> attributes, final AlterMetadataOption... options); T getPF4JStoragePlugin(); } |
@Test public void impersonationEnabledShouldReturnUser() { final HiveConf hiveConf = new HiveConf(); hiveConf.setBoolVar(HIVE_SERVER2_ENABLE_DOAS, true); final SabotContext context = mock(SabotContext.class); final HiveStoragePlugin plugin = new HiveStoragePlugin(hiveConf, context, "foo"); final String userName = plugin.getUsername(TEST_USER_NAME); assertEquals(TEST_USER_NAME, userName); } | public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting HiveStoragePlugin(HiveConf hiveConf, SabotContext context, String name); HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting HiveStoragePlugin(HiveConf hiveConf, SabotContext context, String name); HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(final DatasetHandle datasetHandle, final DatasetMetadata oldDatasetMetadata,
final Map<String, AttributeValue> attributes, final AlterMetadataOption... options); T getPF4JStoragePlugin(); } | HiveStoragePlugin extends BaseHiveStoragePlugin implements StoragePluginCreator.PF4JStoragePlugin, SupportsReadSignature,
SupportsListingDatasets, SupportsAlteringDatasetMetadata, SupportsPF4JStoragePlugin { public String getUsername(String name) { if (isStorageImpersonationEnabled()) { return name; } return SystemUser.SYSTEM_USERNAME; } @VisibleForTesting HiveStoragePlugin(HiveConf hiveConf, SabotContext context, String name); HiveStoragePlugin(HiveConf hiveConf, PluginManager pf4jManager, SabotContext context, String name); @Override boolean containerExists(EntityPath key); @Override ViewTable getView(List<String> tableSchemaPath, SchemaConfig schemaConfig); HiveConf getHiveConf(); @Override boolean hasAccessPermission(String user, NamespaceKey key, DatasetConfig datasetConfig); @Override SourceCapabilities getSourceCapabilities(); @Override Class<? extends StoragePluginRulesFactory> getRulesFactoryClass(); @Override MetadataValidity validateMetadata(BytesOutput signature, DatasetHandle datasetHandle, DatasetMetadata metadata, ValidateMetadataOption... options); @Override Optional<DatasetHandle> getDatasetHandle(EntityPath datasetPath, GetDatasetOption... options); @Override DatasetHandleListing listDatasetHandles(GetDatasetOption... options); @Override PartitionChunkListing listPartitionChunks(DatasetHandle datasetHandle, ListPartitionChunkOption... options); @Override DatasetMetadata getDatasetMetadata(
DatasetHandle datasetHandle,
PartitionChunkListing chunkListing,
GetMetadataOption... options
); @Override BytesOutput provideSignature(DatasetHandle datasetHandle, DatasetMetadata metadata); @Override SourceState getState(); @Override void close(); @Override void start(); String getUsername(String name); @Override Class<? extends HiveProxiedSubScan> getSubScanClass(); @Override HiveProxiedScanBatchCreator createScanBatchCreator(); @Override Class<? extends HiveProxiedOrcScanFilter> getOrcScanFilterClass(); @Override DatasetMetadata alterMetadata(final DatasetHandle datasetHandle, final DatasetMetadata oldDatasetMetadata,
final Map<String, AttributeValue> attributes, final AlterMetadataOption... options); T getPF4JStoragePlugin(); } |
@Test public void testValidRegionFromEndpoint() { Region r = S3FileSystem.getAwsRegionFromEndpoint("s3-eu-central-1.amazonaws.com"); Assert.assertEquals(Region.EU_CENTRAL_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3-us-gov-west-1.amazonaws.com"); Assert.assertEquals(Region.US_GOV_WEST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3.ap-southeast-1.amazonaws.com"); Assert.assertEquals(Region.AP_SOUTHEAST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3.dualstack.ca-central-1.amazonaws.com"); Assert.assertEquals(Region.CA_CENTRAL_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("dremio.s3-control.cn-north-1.amazonaws.com.cn"); Assert.assertEquals(Region.CN_NORTH_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("accountId.s3-control.dualstack.eu-central-1.amazonaws.com"); Assert.assertEquals(Region.EU_CENTRAL_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3-accesspoint.eu-west-1.amazonaws.com"); Assert.assertEquals(Region.EU_WEST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3-accesspoint.dualstack.sa-east-1.amazonaws.com"); Assert.assertEquals(Region.SA_EAST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3-fips.us-gov-west-1.amazonaws.com"); Assert.assertEquals(Region.US_GOV_WEST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3.dualstack.us-gov-east-1.amazonaws.com"); Assert.assertEquals(Region.US_GOV_EAST_1, r); } | static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test public void testInvalidRegionFromEndpoint() { Region r = S3FileSystem.getAwsRegionFromEndpoint("us-west-1"); Assert.assertEquals(Region.US_EAST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("s3-eu-central-1"); Assert.assertEquals(Region.US_EAST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint("abc"); Assert.assertEquals(Region.US_EAST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint(""); Assert.assertEquals(Region.US_EAST_1, r); r = S3FileSystem.getAwsRegionFromEndpoint(null); Assert.assertEquals(Region.US_EAST_1, r); } | static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { static software.amazon.awssdk.regions.Region getAwsRegionFromEndpoint(String endpoint) { return Optional.ofNullable(endpoint) .map(e -> e.toLowerCase(Locale.ROOT)) .filter(e -> e.endsWith(S3_ENDPOINT_END) || e.endsWith(S3_CN_ENDPOINT_END)) .flatMap(e -> software.amazon.awssdk.regions.Region.regions() .stream() .filter(region -> e.contains(region.id())) .findFirst()) .orElse(software.amazon.awssdk.regions.Region.US_EAST_1); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test public void testUnknownContainerExists() { TestExtendedS3FileSystem fs = new TestExtendedS3FileSystem(); AmazonS3 mockedS3Client = mock(AmazonS3.class); when(mockedS3Client.doesBucketExistV2(any(String.class))).thenReturn(true); ListObjectsV2Result result = new ListObjectsV2Result(); result.setBucketName("testunknown"); when(mockedS3Client.listObjectsV2(any(ListObjectsV2Request.class))).thenReturn(result); fs.setCustomClient(mockedS3Client); try { assertNotNull(fs.getUnknownContainer("testunknown")); } catch (IOException e) { fail(e.getMessage()); } } | @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test (expected = ContainerNotFoundException.class) public void testUnknownContainerNotExists() throws IOException { TestExtendedS3FileSystem fs = new TestExtendedS3FileSystem(); AmazonS3 mockedS3Client = mock(AmazonS3.class); when(mockedS3Client.doesBucketExistV2(any(String.class))).thenReturn(false); fs.setCustomClient(mockedS3Client); fs.getUnknownContainer("testunknown"); } | @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test public void ruleSuggestionsAlphabetCharsDelimiter() { Selection selection = new Selection("col", "abbbabbabbaaa", 1, 2); List<SplitRule> rules = recommender.getRules(selection, TEXT); assertEquals(2, rules.size()); compare(MatchType.exact, "bb", false, rules.get(0)); compare(MatchType.exact, "bb", true, rules.get(1)); } | @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } |
@Test (expected = ContainerAccessDeniedException.class) public void testUnknownContainerExistsButNoPermissions() throws IOException { TestExtendedS3FileSystem fs = new TestExtendedS3FileSystem(); AmazonS3 mockedS3Client = mock(AmazonS3.class); when(mockedS3Client.doesBucketExistV2(any(String.class))).thenReturn(true); when(mockedS3Client.listObjectsV2(any(ListObjectsV2Request.class))).thenThrow(new AmazonS3Exception("Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: FF025EBC3B2BF017; S3 Extended Request ID: 9cbmmg2cbPG7+3mXBizXNJ1haZ/0FUhztplqsm/dJPJB32okQRAhRWVWyqakJrKjCNVqzT57IZU=), S3 Extended Request ID: 9cbmmg2cbPG7+3mXBizXNJ1haZ/0FUhztplqsm/dJPJB32okQRAhRWVWyqakJrKjCNVqzT57IZU=")); fs.setCustomClient(mockedS3Client); fs.getUnknownContainer("testunknown"); } | @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { @Override protected ContainerHolder getUnknownContainer(String containerName) throws IOException { boolean containerFound = false; try { if (s3.doesBucketExistV2(containerName)) { final ListObjectsV2Request req = new ListObjectsV2Request() .withMaxKeys(1) .withRequesterPays(isRequesterPays()) .withEncodingType("url") .withBucketName(containerName); containerFound = s3.listObjectsV2(req).getBucketName().equals(containerName); } } catch (AmazonS3Exception e) { if (e.getMessage().contains("Access Denied")) { throw new ContainerAccessDeniedException("aws-bucket", containerName, e); } throw new ContainerNotFoundException("Error while looking up bucket " + containerName, e); } logger.debug("Unknown container '{}' found ? {}", containerName, containerFound); if (!containerFound) { throw new ContainerNotFoundException("Bucket " + containerName + " not found"); } return new BucketCreator(getConf(), containerName).toContainerHolder(); } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test public void testVerifyCredentialsRetry() { PowerMockito.mockStatic(StsClient.class); StsClient mockedClient = mock(StsClient.class); StsClientBuilder mockedClientBuilder = mock(StsClientBuilder.class); when(mockedClientBuilder.credentialsProvider(any(AwsCredentialsProvider.class))).thenReturn(mockedClientBuilder); when(mockedClientBuilder.region(any(Region.class))).thenReturn(mockedClientBuilder); when(mockedClientBuilder.build()).thenReturn(mockedClient); when(StsClient.builder()).thenReturn(mockedClientBuilder); TestExtendedS3FileSystem fs = new TestExtendedS3FileSystem(); AtomicInteger retryAttemptNo = new AtomicInteger(1); when(mockedClient.getCallerIdentity(any(GetCallerIdentityRequest.class))).then(invocationOnMock -> { if (retryAttemptNo.incrementAndGet() < 10) { throw SdkClientException.builder().message("Unable to load credentials from service endpoint.").build(); } return null; }); fs.verifyCredentials(new Configuration()); assertEquals(10, retryAttemptNo.get()); } | protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test(expected = RuntimeException.class) public void testVerifyCredentialsNoRetryOnAuthnError() { PowerMockito.mockStatic(StsClient.class); StsClient mockedClient = mock(StsClient.class); StsClientBuilder mockedClientBuilder = mock(StsClientBuilder.class); when(mockedClientBuilder.credentialsProvider(any(AwsCredentialsProvider.class))).thenReturn(mockedClientBuilder); when(mockedClientBuilder.region(any(Region.class))).thenReturn(mockedClientBuilder); when(mockedClientBuilder.build()).thenReturn(mockedClient); when(StsClient.builder()).thenReturn(mockedClientBuilder); TestExtendedS3FileSystem fs = new TestExtendedS3FileSystem(); AtomicInteger retryAttemptNo = new AtomicInteger(0); when(mockedClient.getCallerIdentity(any(GetCallerIdentityRequest.class))).then(invocationOnMock -> { retryAttemptNo.incrementAndGet(); throw StsException.builder().message("The security token included in the request is invalid. (Service: Sts, Status Code: 403, Request ID: a7e2e92e-5ebb-4343-87a1-21e4d64edcd4)").build(); }); fs.verifyCredentials(new Configuration()); assertEquals(1, retryAttemptNo.get()); } | protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } S3FileSystem(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); } | S3FileSystem extends ContainerFileSystem implements MayProvideAsyncStream { protected void verifyCredentials(Configuration conf) throws RuntimeException { AwsCredentialsProvider awsCredentialsProvider = getAsync2Provider(conf); final StsClientBuilder stsClientBuilder = StsClient.builder() .credentialsProvider(awsCredentialsProvider) .region(getAWSRegionFromConfigurationOrDefault(conf)); try (StsClient stsClient = stsClientBuilder.build()) { retryer.call(() -> { GetCallerIdentityRequest request = GetCallerIdentityRequest.builder().build(); stsClient.getCallerIdentity(request); return true; }); } catch (Retryer.OperationFailedAfterRetriesException e) { throw new RuntimeException("Credential Verification failed.", e); } } S3FileSystem(); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override boolean supportsAsync(); @Override AsyncByteReader getAsyncByteReader(Path path, String version); @Override void close(); static final String S3_PERMISSION_ERROR_MSG; } |
@Test public void transformContainerPathWithColon() { final Path path = new Path("s3a: final String containerName = "qa1.dremio.com"; final Path transformed = ContainerFileSystem.transform(path, containerName); Assert.assertEquals(new Path("/qa1.dremio.com/test:breaks"), transformed); } | @VisibleForTesting static Path transform(Path path, String containerName) { final String relativePath = removeLeadingSlash(Path.getPathWithoutSchemeAndAuthority(path).toString()); final Path containerPath = new Path(Path.SEPARATOR + containerName); return Strings.isNullOrEmpty(relativePath) ? containerPath : new Path(containerPath, new Path(null, null, relativePath)); } | ContainerFileSystem extends FileSystem { @VisibleForTesting static Path transform(Path path, String containerName) { final String relativePath = removeLeadingSlash(Path.getPathWithoutSchemeAndAuthority(path).toString()); final Path containerPath = new Path(Path.SEPARATOR + containerName); return Strings.isNullOrEmpty(relativePath) ? containerPath : new Path(containerPath, new Path(null, null, relativePath)); } } | ContainerFileSystem extends FileSystem { @VisibleForTesting static Path transform(Path path, String containerName) { final String relativePath = removeLeadingSlash(Path.getPathWithoutSchemeAndAuthority(path).toString()); final Path containerPath = new Path(Path.SEPARATOR + containerName); return Strings.isNullOrEmpty(relativePath) ? containerPath : new Path(containerPath, new Path(null, null, relativePath)); } protected ContainerFileSystem(String scheme, String containerName, Predicate<CorrectableFileStatus> listFileStatusPredicate); } | ContainerFileSystem extends FileSystem { @VisibleForTesting static Path transform(Path path, String containerName) { final String relativePath = removeLeadingSlash(Path.getPathWithoutSchemeAndAuthority(path).toString()); final Path containerPath = new Path(Path.SEPARATOR + containerName); return Strings.isNullOrEmpty(relativePath) ? containerPath : new Path(containerPath, new Path(null, null, relativePath)); } protected ContainerFileSystem(String scheme, String containerName, Predicate<CorrectableFileStatus> listFileStatusPredicate); void refreshFileSystems(); List<ContainerFailure> getSubFailures(); @Override final void initialize(URI name, Configuration conf); boolean containerExists(final String containerName); static String getContainerName(Path path); static Path pathWithoutContainer(Path path); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override FileStatus[] listStatus(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override boolean exists(Path f); @Override FileStatus getFileStatus(Path f); @Override String getScheme(); } | ContainerFileSystem extends FileSystem { @VisibleForTesting static Path transform(Path path, String containerName) { final String relativePath = removeLeadingSlash(Path.getPathWithoutSchemeAndAuthority(path).toString()); final Path containerPath = new Path(Path.SEPARATOR + containerName); return Strings.isNullOrEmpty(relativePath) ? containerPath : new Path(containerPath, new Path(null, null, relativePath)); } protected ContainerFileSystem(String scheme, String containerName, Predicate<CorrectableFileStatus> listFileStatusPredicate); void refreshFileSystems(); List<ContainerFailure> getSubFailures(); @Override final void initialize(URI name, Configuration conf); boolean containerExists(final String containerName); static String getContainerName(Path path); static Path pathWithoutContainer(Path path); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize, short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override RemoteIterator<LocatedFileStatus> listLocatedStatus(Path f); @Override RemoteIterator<LocatedFileStatus> listFiles(Path f, boolean recursive); @Override FileStatus[] listStatus(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override boolean exists(Path f); @Override FileStatus getFileStatus(Path f); @Override String getScheme(); } |
@Test public void testAsyncHttpClientClosedError() { AsyncHttpClient client = mock(AsyncHttpClient.class); when(client.isClosed()).thenReturn(true); LocalDateTime versionDate = LocalDateTime.now(ZoneId.of("GMT")).minusDays(2); AzureAsyncReader azureAsyncReader = spy(new AzureAsyncReader( "account", new Path("container/directory/file_00.parquet"), getMockAuthTokenProvider(), String.valueOf(versionDate.atZone(ZoneId.of("GMT")).toInstant().toEpochMilli()), false, client )); try { azureAsyncReader.readFully(0, Unpooled.buffer(1), 0, 1); fail("Operation shouldn't proceed if client is closed"); } catch (RuntimeException e) { assertEquals("AsyncHttpClient is closed", e.getMessage()); } } | @Override public CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len) { return read(offset, dst, dstOffset, len, 0); } | AzureAsyncReader extends ExponentialBackoff implements AutoCloseable, AsyncByteReader { @Override public CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len) { return read(offset, dst, dstOffset, len, 0); } } | AzureAsyncReader extends ExponentialBackoff implements AutoCloseable, AsyncByteReader { @Override public CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len) { return read(offset, dst, dstOffset, len, 0); } AzureAsyncReader(final String accountName,
final Path path,
final AzureAuthTokenProvider authProvider,
final String version,
final boolean isSecure,
final AsyncHttpClient asyncHttpClient); } | AzureAsyncReader extends ExponentialBackoff implements AutoCloseable, AsyncByteReader { @Override public CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len) { return read(offset, dst, dstOffset, len, 0); } AzureAsyncReader(final String accountName,
final Path path,
final AzureAuthTokenProvider authProvider,
final String version,
final boolean isSecure,
final AsyncHttpClient asyncHttpClient); @Override CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len); CompletableFuture<Void> read(long offset, ByteBuf dst, int dstOffset, long len, int retryAttemptNum); @Override void close(); } | AzureAsyncReader extends ExponentialBackoff implements AutoCloseable, AsyncByteReader { @Override public CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len) { return read(offset, dst, dstOffset, len, 0); } AzureAsyncReader(final String accountName,
final Path path,
final AzureAuthTokenProvider authProvider,
final String version,
final boolean isSecure,
final AsyncHttpClient asyncHttpClient); @Override CompletableFuture<Void> readFully(long offset, ByteBuf dst, int dstOffset, int len); CompletableFuture<Void> read(long offset, ByteBuf dst, int dstOffset, long len, int retryAttemptNum); @Override void close(); } |
@Test public void testListContainers() throws IOException, ExecutionException, InterruptedException { AsyncHttpClient client = mock(AsyncHttpClient.class); Response response = mock(Response.class); when(response.getHeader(any(String.class))).thenReturn(""); HttpResponseStatus status = mock(HttpResponseStatus.class); when(status.getStatusCode()).thenReturn(206); byte[] dfsCoreResponseBodyBytesPage1 = readStaticResponse("dfs-core-container-response-page1.json"); RandomBytesResponseDispatcher dfsCoreResponseDispatcherPage1 = new RandomBytesResponseDispatcher(dfsCoreResponseBodyBytesPage1); byte[] dfsCoreResponseBodyBytesPage2 = readStaticResponse("dfs-core-container-response-page2.json"); RandomBytesResponseDispatcher dfsCoreResponseDispatcherPage2 = new RandomBytesResponseDispatcher(dfsCoreResponseBodyBytesPage2); byte[] dfsCoreEmptyResponseBytes = readStaticResponse("dfs-core-container-empty.json"); RandomBytesResponseDispatcher dfsCoreEmptyResponseDispatcher = new RandomBytesResponseDispatcher(dfsCoreEmptyResponseBytes); CompletableFuture<Response> future = CompletableFuture.completedFuture(response); ListenableFuture<Response> resFuture = mock(ListenableFuture.class); when(resFuture.toCompletableFuture()).thenReturn(future); when(resFuture.get()).thenReturn(response); when(client.executeRequest(any(Request.class), any(AsyncCompletionHandler.class))).then(invocationOnMock -> { Request req = invocationOnMock.getArgument(0, Request.class); AsyncCompletionHandler handler = invocationOnMock.getArgument(1, AsyncCompletionHandler.class); assertTrue(req.getUrl().startsWith("https: assertNotNull(req.getHeaders().get("Date")); assertNotNull(req.getHeaders().get("x-ms-client-request-id")); assertEquals("2019-07-07", req.getHeaders().get("x-ms-version")); assertEquals("Bearer testtoken", req.getHeaders().get("Authorization")); List<NameValuePair> queryParams = URLEncodedUtils.parse(new URI(req.getUrl()), StandardCharsets.UTF_8); String continuationKey = queryParams.stream() .filter(param -> param.getName().equalsIgnoreCase("continuation")).findAny() .map(NameValuePair::getValue).orElse(""); if ("page1container1".equals(continuationKey)) { when(response.getHeader("x-ms-continuation")).thenReturn("page2container1"); while (dfsCoreResponseDispatcherPage1.isNotFinished()) { handler.onBodyPartReceived(dfsCoreResponseDispatcherPage1.getNextBodyPart()); } } else if ("page2container1".equals(continuationKey)) { when(response.getHeader("x-ms-continuation")).thenReturn(""); while (dfsCoreResponseDispatcherPage2.isNotFinished()) { handler.onBodyPartReceived(dfsCoreResponseDispatcherPage2.getNextBodyPart()); } } else { when(response.getHeader("x-ms-continuation")).thenReturn("page1container1"); while (dfsCoreEmptyResponseDispatcher.isNotFinished()) { handler.onBodyPartReceived(dfsCoreEmptyResponseDispatcher.getNextBodyPart()); } } handler.onStatusReceived(status); handler.onCompleted(response); return resFuture; }); AzureStorageFileSystem parentClass = mock(AzureStorageFileSystem.class); AzureAuthTokenProvider authTokenProvider = getMockAuthTokenProvider(); AzureAsyncContainerProvider containerProvider = new AzureAsyncContainerProvider( client, "azurestoragev2hier", authTokenProvider, parentClass, true); List<String> receivedContainers = containerProvider.getContainerCreators() .map(AzureStorageFileSystem.ContainerCreatorImpl.class::cast) .map(AzureStorageFileSystem.ContainerCreatorImpl::getName) .collect(Collectors.toList()); List<String> expectedContainers = Arrays.asList("page1container1", "page1container2", "page1container3", "page2container1", "page2container2", "page2container3"); assertEquals(expectedContainers, receivedContainers); } | @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } |
@Test public void testListContainersWithRetry() throws IOException, ExecutionException, InterruptedException { AsyncHttpClient client = mock(AsyncHttpClient.class); Response response = mock(Response.class); when(response.getHeader(any(String.class))).thenReturn(""); HttpResponseStatus status = mock(HttpResponseStatus.class); when(status.getStatusCode()).thenReturn(206); HttpResponseStatus failedStatus = mock(HttpResponseStatus.class); when(failedStatus.getStatusCode()).thenReturn(500); byte[] dfsCoreResponseBodyBytes = readStaticResponse("dfs-core-container-response-page1.json"); RandomBytesResponseDispatcher dfsCoreResponseDispatcher = new RandomBytesResponseDispatcher(dfsCoreResponseBodyBytes); CompletableFuture<Response> future = CompletableFuture.completedFuture(response); ListenableFuture<Response> resFuture = mock(ListenableFuture.class); when(resFuture.toCompletableFuture()).thenReturn(future); when(resFuture.get()).thenReturn(response); AtomicInteger retryAttemptNo = new AtomicInteger(0); when(client.executeRequest(any(Request.class), any(AsyncCompletionHandler.class))).then(invocationOnMock -> { AsyncCompletionHandler handler = invocationOnMock.getArgument(1, AsyncCompletionHandler.class); if (retryAttemptNo.incrementAndGet() < 10) { handler.onStatusReceived(failedStatus); } else { while (dfsCoreResponseDispatcher.isNotFinished()) { handler.onBodyPartReceived(dfsCoreResponseDispatcher.getNextBodyPart()); } handler.onStatusReceived(status); } handler.onCompleted(response); return resFuture; }); AzureStorageFileSystem parentClass = mock(AzureStorageFileSystem.class); AzureAuthTokenProvider authTokenProvider = getMockAuthTokenProvider(); AzureAsyncContainerProvider containerProvider = new AzureAsyncContainerProvider( client, "azurestoragev2hier", authTokenProvider, parentClass, true); List<String> receivedContainers = containerProvider.getContainerCreators() .map(AzureStorageFileSystem.ContainerCreatorImpl.class::cast) .map(AzureStorageFileSystem.ContainerCreatorImpl::getName) .collect(Collectors.toList()); List<String> expectedContainers = Arrays.asList("page1container1", "page1container2", "page1container3"); assertEquals(expectedContainers, receivedContainers); } | @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public Stream<ContainerFileSystem.ContainerCreator> getContainerCreators() { Iterator<String> containerIterator = new DFSContainerIterator(asyncHttpClient, account, authProvider, isSecure, retryer); return StreamSupport.stream(Spliterators.spliteratorUnknownSize(containerIterator, Spliterator.ORDERED), false) .map(c -> new AzureStorageFileSystem.ContainerCreatorImpl(parent, c)); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } |
@Test public void testDoesContainerExists() throws ExecutionException, InterruptedException { AzureStorageFileSystem parentClass = mock(AzureStorageFileSystem.class); AzureAuthTokenProvider authTokenProvider = getMockAuthTokenProvider(); AsyncHttpClient client = mock(AsyncHttpClient.class); Response response = mock(Response.class); when(response.getHeader(any(String.class))).thenReturn(""); when(response.getStatusCode()).thenReturn(200); ListenableFuture<Response> future = mock(ListenableFuture.class); when(future.get()).thenReturn(response); when(client.executeRequest(any(Request.class))).thenReturn(future); AzureAsyncContainerProvider containerProvider = new AzureAsyncContainerProvider( client, "azurestoragev2hier", authTokenProvider, parentClass, true); containerProvider.assertContainerExists("container"); } | @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } |
@Test public void testDoesContainerExistsNotFound() throws ExecutionException, InterruptedException { AzureStorageFileSystem parentClass = mock(AzureStorageFileSystem.class); AzureAuthTokenProvider authTokenProvider = getMockAuthTokenProvider(); AsyncHttpClient client = mock(AsyncHttpClient.class); Response response = mock(Response.class); when(response.getHeader(any(String.class))).thenReturn(""); when(response.getStatusCode()).thenReturn(404); when(response.getStatusText()).thenReturn("The specified filesystem does not exist."); ListenableFuture<Response> future = mock(ListenableFuture.class); when(future.get()).thenReturn(response); when(client.executeRequest(any(Request.class))).thenReturn(future); AzureAsyncContainerProvider containerProvider = new AzureAsyncContainerProvider( client, "azurestoragev2hier", authTokenProvider, parentClass, true); try { containerProvider.assertContainerExists("container"); fail("Expecting exception"); } catch (Retryer.OperationFailedAfterRetriesException e) { assertEquals(ContainerNotFoundException.class, e.getCause().getClass()); assertEquals("Unable to find container container - [404 The specified filesystem does not exist.]", e.getCause().getMessage()); } verify(client, times(1)).executeRequest(any(Request.class)); } | @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } |
@Test public void testDoesContainerExistsAccessDenied() throws ExecutionException, InterruptedException { AzureStorageFileSystem parentClass = mock(AzureStorageFileSystem.class); AzureAuthTokenProvider authTokenProvider = getMockAuthTokenProvider(); AsyncHttpClient client = mock(AsyncHttpClient.class); Response response = mock(Response.class); when(response.getHeader(any(String.class))).thenReturn(""); when(response.getStatusCode()).thenReturn(403); when(response.getStatusText()).thenReturn("Forbidden, InsufficientAccountPermissions, \"The account being accessed does not have sufficient permissions to execute this operation.\""); ListenableFuture<Response> future = mock(ListenableFuture.class); when(future.get()).thenReturn(response); when(client.executeRequest(any(Request.class))).thenReturn(future); AzureAsyncContainerProvider containerProvider = new AzureAsyncContainerProvider( client, "azurestoragev2hier", authTokenProvider, parentClass, true); try { containerProvider.assertContainerExists("container"); fail("Expecting exception"); } catch (Retryer.OperationFailedAfterRetriesException e) { assertTrue(e.getCause() instanceof ContainerAccessDeniedException); assertEquals("Access to container container denied - [403 Forbidden, InsufficientAccountPermissions, \"The account being accessed does not have sufficient permissions to execute this operation.\"]", e.getCause().getMessage()); } verify(client, times(1)).executeRequest(any(Request.class)); } | @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } | AzureAsyncContainerProvider implements ContainerProvider { @Override public void assertContainerExists(final String containerName) { logger.debug("Checking for missing azure container " + account + ":" + containerName); final Request req = new RequestBuilder(HttpConstants.Methods.HEAD) .addHeader("x-ms-date", toHttpDateFormat(System.currentTimeMillis())) .addHeader("x-ms-version", XMS_VERSION) .addHeader("Content-Length", 0) .addHeader("x-ms-client-request-id", UUID.randomUUID().toString()) .setUrl(AzureAsyncHttpClientUtils.getBaseEndpointURL(account, true) + "/" + containerName) .addQueryParam("resource", "filesystem") .addQueryParam("timeout", String.valueOf(requestTimeoutSeconds)).build(); req.getHeaders().add("Authorization", authProvider.getAuthzHeaderValue(req)); retryer.call(() -> { Response response = asyncHttpClient.executeRequest(req).get(); int status = response.getStatusCode(); if (status >= 500) { logger.error("Error while checking for azure container " + account + ":" + containerName + " status code " + status); throw new RuntimeException(String.format("Error response %d while checking for existence of container %s", status, containerName)); } if (status == 200) { logger.debug("Azure container is found valid " + account + ":" + containerName); } else if (status == 403) { throw new ContainerAccessDeniedException(String.format("Access to container %s denied - [%d %s]", containerName, status, response.getStatusText())); } else { throw new ContainerNotFoundException(String.format("Unable to find container %s - [%d %s]", containerName, status, response.getStatusText())); } return true; }); } AzureAsyncContainerProvider(final AsyncHttpClient asyncHttpClient,
final String account,
final AzureAuthTokenProvider authProvider,
final AzureStorageFileSystem parent,
boolean isSecure); @Override Stream<ContainerFileSystem.ContainerCreator> getContainerCreators(); @Override void assertContainerExists(final String containerName); } |
@Test public void ruleSuggestionsPipeDelimiter() { Selection selection = new Selection("col", "1|2|3|4|5", 1, 1); List<SplitRule> rules = recommender.getRules(selection, TEXT); assertEquals(1, rules.size()); compare(MatchType.exact, "|", false, rules.get(0)); } | @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } | SplitRecommender extends Recommender<SplitRule, Selection> { @Override public List<SplitRule> getRules(Selection selection, DataType selColType) { checkArgument(selColType == DataType.TEXT, "Split is supported only on TEXT type columns"); List<SplitRule> rules = new ArrayList<>(); String seltext = selection.getCellText().substring(selection.getOffset(), selection.getOffset() + selection.getLength()); rules.add(new SplitRule(seltext, exact, false)); if (!seltext.toUpperCase().equals(seltext.toLowerCase())) { rules.add(new SplitRule(seltext, exact, true)); } return rules; } @Override List<SplitRule> getRules(Selection selection, DataType selColType); TransformRuleWrapper<SplitRule> wrapRule(SplitRule rule); } |
@Test public void testSameInstance() throws InterruptedException { ExecutorService ex = Executors.newFixedThreadPool(10); final Set<Integer> objectIdentities = new ConcurrentSkipListSet<>(); CountDownLatch latch = new CountDownLatch(100); for (int i=0; i<100; i++) { ex.execute(() -> { objectIdentities.add(System.identityHashCode(AsyncHttpClientProvider.getInstance())); latch.countDown(); }); } latch.await(5, TimeUnit.MINUTES); assertEquals(1, objectIdentities.size()); ex.shutdownNow(); } | public static AsyncHttpClient getInstance(){ return SingletonHelper.INSTANCE; } | AsyncHttpClientProvider { public static AsyncHttpClient getInstance(){ return SingletonHelper.INSTANCE; } } | AsyncHttpClientProvider { public static AsyncHttpClient getInstance(){ return SingletonHelper.INSTANCE; } } | AsyncHttpClientProvider { public static AsyncHttpClient getInstance(){ return SingletonHelper.INSTANCE; } static AsyncHttpClient getInstance(); } | AsyncHttpClientProvider { public static AsyncHttpClient getInstance(){ return SingletonHelper.INSTANCE; } static AsyncHttpClient getInstance(); static final int DEFAULT_REQUEST_TIMEOUT; } |
@Test public void testGetAuthzHeaderValue() { String authzHeaderValue = authTokenProvider.getAuthzHeaderValue(prepareTestRequest()); assertEquals("SharedKey mock-account:ZwovG4J+nCDc3w58WPei6fvJBQsO96YojteJncy0wwI=", authzHeaderValue); } | @Override public String getAuthzHeaderValue(final Request req) { try { final URL url = new URL(req.getUrl()); final Map<String, String> headersMap = new HashMap<>(); req.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); return this.storageSharedKeyCredential.generateAuthorizationHeader(url, req.getMethod(), headersMap); } catch (MalformedURLException e) { throw new IllegalStateException("The request URL is invalid ", e); } } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public String getAuthzHeaderValue(final Request req) { try { final URL url = new URL(req.getUrl()); final Map<String, String> headersMap = new HashMap<>(); req.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); return this.storageSharedKeyCredential.generateAuthorizationHeader(url, req.getMethod(), headersMap); } catch (MalformedURLException e) { throw new IllegalStateException("The request URL is invalid ", e); } } } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public String getAuthzHeaderValue(final Request req) { try { final URL url = new URL(req.getUrl()); final Map<String, String> headersMap = new HashMap<>(); req.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); return this.storageSharedKeyCredential.generateAuthorizationHeader(url, req.getMethod(), headersMap); } catch (MalformedURLException e) { throw new IllegalStateException("The request URL is invalid ", e); } } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public String getAuthzHeaderValue(final Request req) { try { final URL url = new URL(req.getUrl()); final Map<String, String> headersMap = new HashMap<>(); req.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); return this.storageSharedKeyCredential.generateAuthorizationHeader(url, req.getMethod(), headersMap); } catch (MalformedURLException e) { throw new IllegalStateException("The request URL is invalid ", e); } } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); @Override boolean checkAndUpdateToken(); @Override String getAuthzHeaderValue(final Request req); @Override boolean isCloseToExpiry(); } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public String getAuthzHeaderValue(final Request req) { try { final URL url = new URL(req.getUrl()); final Map<String, String> headersMap = new HashMap<>(); req.getHeaders().forEach(header -> headersMap.put(header.getKey(), header.getValue())); return this.storageSharedKeyCredential.generateAuthorizationHeader(url, req.getMethod(), headersMap); } catch (MalformedURLException e) { throw new IllegalStateException("The request URL is invalid ", e); } } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); @Override boolean checkAndUpdateToken(); @Override String getAuthzHeaderValue(final Request req); @Override boolean isCloseToExpiry(); } |
@Test public void testCheckAndUpdate() { assertFalse("Shared key token is static. There shouldn't ever be an update required", authTokenProvider.checkAndUpdateToken()); } | @Override public boolean checkAndUpdateToken() { return false; } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean checkAndUpdateToken() { return false; } } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean checkAndUpdateToken() { return false; } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean checkAndUpdateToken() { return false; } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); @Override boolean checkAndUpdateToken(); @Override String getAuthzHeaderValue(final Request req); @Override boolean isCloseToExpiry(); } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean checkAndUpdateToken() { return false; } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); @Override boolean checkAndUpdateToken(); @Override String getAuthzHeaderValue(final Request req); @Override boolean isCloseToExpiry(); } |
@Test public void testIsCloseToExpiry() { assertFalse("Shared key token never expires", authTokenProvider.isCloseToExpiry()); } | @Override public boolean isCloseToExpiry() { return false; } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean isCloseToExpiry() { return false; } } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean isCloseToExpiry() { return false; } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean isCloseToExpiry() { return false; } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); @Override boolean checkAndUpdateToken(); @Override String getAuthzHeaderValue(final Request req); @Override boolean isCloseToExpiry(); } | AzureSharedKeyAuthTokenProvider implements AzureAuthTokenProvider { @Override public boolean isCloseToExpiry() { return false; } AzureSharedKeyAuthTokenProvider(final String accountName, final String key); @Override boolean checkAndUpdateToken(); @Override String getAuthzHeaderValue(final Request req); @Override boolean isCloseToExpiry(); } |
@Test public void testToProtobuFileStatus() throws IOException { FileStatus status = TEST_FILE_STATUS; DFS.FileStatus result = RemoteNodeFileSystem.toProtoFileStatus(status); assertEquals(TEST_PATH_STRING, result.getPath()); assertEquals(1024,result.getLength()); assertFalse(result.getIsDirectory()); assertEquals(1, result.getBlockReplication()); assertEquals(4096, result.getBlockSize()); assertEquals(1453325758, result.getAccessTime()); assertEquals(1453325757, result.getModificationTime()); assertEquals(0644, result.getPermission()); assertEquals("testowner", result.getOwner()); assertEquals("testgroup", result.getGroup()); assertFalse(result.hasSymlink()); } | static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } | RemoteNodeFileSystem extends FileSystem { static DFS.FileStatus toProtoFileStatus(FileStatus status) throws IOException { DFS.FileStatus.Builder builder = DFS.FileStatus.newBuilder(); builder .setLength(status.getLen()) .setIsDirectory(status.isDirectory()) .setBlockReplication(status.getReplication()) .setBlockSize(status.getBlockSize()) .setModificationTime(status.getModificationTime()) .setAccessTime(status.getAccessTime()); if (status.getPath() != null) { builder = builder.setPath(status.getPath().toUri().getPath()); } if (status.getPermission() != null) { builder = builder.setPermission(status.getPermission().toExtendedShort()); } if (status.getOwner() != null) { builder = builder.setOwner(status.getOwner()); } if (status.getGroup() != null) { builder = builder.setGroup(status.getGroup()); } if (status.isSymlink()) { builder = builder.setSymlink(status.getSymlink().toString()); } return builder.build(); } RemoteNodeFileSystem(FabricCommandRunner runner, BufferAllocator allocator); @Override void initialize(URI name, Configuration conf); @Override URI getUri(); @Override FSDataInputStream open(Path f, int bufferSize); @Override FSDataOutputStream create(Path f, FsPermission permission, boolean overwrite, int bufferSize,
short replication, long blockSize, Progressable progress); @Override FSDataOutputStream append(Path f, int bufferSize, Progressable progress); @Override boolean rename(Path src, Path dst); @Override boolean delete(Path f, boolean recursive); @Override FileStatus[] listStatus(Path f); @Override RemoteIterator<FileStatus> listStatusIterator(final Path f); @Override void setWorkingDirectory(Path newDir); @Override Path getWorkingDirectory(); @Override boolean mkdirs(Path f, FsPermission permission); @Override FileStatus getFileStatus(Path f); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.