|
33 | 33 | import java.util.Collection;
|
34 | 34 | import java.util.Properties;
|
35 | 35 |
|
| 36 | +import org.apache.phoenix.compile.ExplainPlan; |
| 37 | +import org.apache.phoenix.compile.ExplainPlanAttributes; |
| 38 | +import org.apache.phoenix.jdbc.PhoenixPreparedStatement; |
36 | 39 | import org.apache.phoenix.util.PropertiesUtil;
|
37 | 40 | import org.junit.Test;
|
38 | 41 | import org.junit.experimental.categories.Category;
|
@@ -142,26 +145,54 @@ public void testCoerceLongToDecimal2() throws Exception {
|
142 | 145 | conn.close();
|
143 | 146 | }
|
144 | 147 | }
|
145 |
| - |
| 148 | + |
146 | 149 | @Test
|
147 | 150 | public void testCoerceTinyIntToSmallInt() throws Exception {
|
148 |
| - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND a_byte >= a_short"; |
| 151 | + String query = "SELECT entity_id FROM " + tableName |
| 152 | + + " WHERE organization_id=? AND a_byte >= a_short"; |
149 | 153 | String url = getUrl();
|
150 | 154 | Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
|
151 |
| - Connection conn = DriverManager.getConnection(url, props); |
152 |
| - try { |
| 155 | + try (Connection conn = DriverManager.getConnection(url, props)) { |
153 | 156 | PreparedStatement statement = conn.prepareStatement(query);
|
154 | 157 | statement.setString(1, tenantId);
|
155 | 158 | ResultSet rs = statement.executeQuery();
|
156 | 159 | assertTrue(rs.next());
|
157 | 160 | assertEquals(ROW9, rs.getString(1));
|
158 | 161 | assertFalse(rs.next());
|
159 |
| - } finally { |
160 |
| - conn.close(); |
| 162 | + |
| 163 | + ExplainPlan plan = statement.unwrap(PhoenixPreparedStatement.class).optimizeQuery(query) |
| 164 | + .getExplainPlan(); |
| 165 | + ExplainPlanAttributes explainPlanAttributes = plan.getPlanStepsAsAttributes(); |
| 166 | + assertEquals(tableName, explainPlanAttributes.getTableName()); |
| 167 | + assertEquals("PARALLEL 1-WAY", explainPlanAttributes.getIteratorTypeAndScanSize()); |
| 168 | + assertEquals("RANGE SCAN ", explainPlanAttributes.getExplainScanType()); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + @Test |
| 173 | + public void testCoerceWithRangeScan() throws Exception { |
| 174 | + String query = "SELECT entity_id FROM " + tableName |
| 175 | + + " WHERE organization_id = cast(? as varchar) AND " |
| 176 | + + "cast(a_byte as smallint) >= a_short"; |
| 177 | + String url = getUrl(); |
| 178 | + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); |
| 179 | + try (Connection conn = DriverManager.getConnection(url, props)) { |
| 180 | + PreparedStatement statement = conn.prepareStatement(query); |
| 181 | + statement.setString(1, tenantId); |
| 182 | + ResultSet rs = statement.executeQuery(); |
| 183 | + assertTrue(rs.next()); |
| 184 | + assertEquals(ROW9, rs.getString(1)); |
| 185 | + assertFalse(rs.next()); |
| 186 | + |
| 187 | + ExplainPlan plan = statement.unwrap(PhoenixPreparedStatement.class).optimizeQuery(query) |
| 188 | + .getExplainPlan(); |
| 189 | + ExplainPlanAttributes explainPlanAttributes = plan.getPlanStepsAsAttributes(); |
| 190 | + assertEquals(tableName, explainPlanAttributes.getTableName()); |
| 191 | + assertEquals("PARALLEL 1-WAY", explainPlanAttributes.getIteratorTypeAndScanSize()); |
| 192 | + assertEquals("RANGE SCAN ", explainPlanAttributes.getExplainScanType()); |
161 | 193 | }
|
162 | 194 | }
|
163 | 195 |
|
164 |
| - |
165 | 196 | @Test
|
166 | 197 | public void testCoerceDateToBigInt() throws Exception {
|
167 | 198 | Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
|
|
0 commit comments