Java Code Examples for org.apache.phoenix.util.SchemaUtil#getPhysicalTableName()
The following examples show how to use
org.apache.phoenix.util.SchemaUtil#getPhysicalTableName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MutableIndexFailureWithNamespaceIT.java From phoenix with Apache License 2.0 | 6 votes |
@BeforeClass public static synchronized void doSetup() throws Exception { Map<String, String> serverProps = getServerProps(); serverProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.TRUE.toString()); Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(3); clientProps.put(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.TRUE.toString()); clientProps.put(HConstants.HBASE_CLIENT_RETRIES_NUMBER, "2"); clientProps.put(QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB, Boolean.FALSE.toString()); NUM_SLAVES_BASE = 4; setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator())); TableName systemTable = SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, true); indexRebuildTaskRegionEnvironment = getUtility() .getRSForFirstRegionInTable(systemTable).getRegions(systemTable).get(0).getCoprocessorHost() .findCoprocessorEnvironment(MetaDataRegionObserver.class.getName()); MetaDataRegionObserver.initRebuildIndexConnectionProps(indexRebuildTaskRegionEnvironment.getConfiguration()); }
Example 2
Source File: LocalIndexIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testLocalIndexTableRegionSplitPolicyAndSplitKeys() throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); String indexPhysicalTableName = physicalTableName.getNameAsString(); createBaseTable(tableName, null,"('e','i','o')"); Connection conn1 = getConnection(); Connection conn2 = getConnection(); conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); conn2.createStatement().executeQuery("SELECT * FROM " + tableName).next(); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); TableDescriptor htd = admin .getDescriptor(TableName.valueOf(indexPhysicalTableName)); assertEquals(IndexRegionSplitPolicy.class.getName(), htd.getValue(TableDescriptorBuilder.SPLIT_POLICY)); try(org.apache.hadoop.hbase.client.Connection c = ConnectionFactory.createConnection(admin.getConfiguration())) { try (RegionLocator userTable= c.getRegionLocator(SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped))) { try (RegionLocator indxTable = c.getRegionLocator(TableName.valueOf(indexPhysicalTableName))) { assertArrayEquals("Both user table and index table should have same split keys.", userTable.getStartKeys(), indxTable.getStartKeys()); } } } }
Example 3
Source File: SnapshotScanner.java From phoenix with Apache License 2.0 | 5 votes |
public SnapshotScanner(Configuration conf, FileSystem fs, Path rootDir, TableDescriptor htd, RegionInfo hri, Scan scan) throws Throwable{ LOGGER.info("Creating SnapshotScanner for region: " + hri); scan.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED); values = new ArrayList<>(); this.region = HRegion.openHRegion(conf, fs, rootDir, hri, htd, null, null, null); this.scan = scan; RegionCoprocessorEnvironment snapshotEnv = getSnapshotContextEnvironment(conf); // Collect statistics during scan if ANALYZE_TABLE attribute is set if (ScanUtil.isAnalyzeTable(scan)) { this.scanner = region.getScanner(scan); PhoenixConnection connection = (PhoenixConnection) ConnectionUtil.getInputConnection(conf, new Properties()); String tableName = region.getTableDescriptor().getTableName().getNameAsString(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES, conf); Table table = connection.getQueryServices().getTable(physicalTableName.getName()); StatisticsWriter statsWriter = StatisticsWriter.newWriter(connection, tableName, HConstants.LATEST_TIMESTAMP); statisticsCollector = new DefaultStatisticsCollector(conf, region, tableName, null, null, null, statsWriter, table); } else if (scan.getAttribute(BaseScannerRegionObserver.NON_AGGREGATE_QUERY) != null) { RegionScannerFactory regionScannerFactory = new NonAggregateRegionScannerFactory(snapshotEnv); this.scanner = regionScannerFactory.getRegionScanner(scan, region.getScanner(scan)); statisticsCollector = new NoOpStatisticsCollector(); } else { /* future work : Snapshot M/R jobs for aggregate queries*/ throw new UnsupportedOperationException("Snapshot M/R jobs not available for aggregate queries"); } statisticsCollector.init(); region.startRegionOperation(); }
Example 4
Source File: StatisticsWriter.java From phoenix with Apache License 2.0 | 5 votes |
public static StatisticsWriter newWriter(PhoenixConnection conn, String tableName, long clientTimeStamp) throws SQLException { Configuration configuration = conn.getQueryServices().getConfiguration(); long newClientTimeStamp = determineClientTimeStamp(configuration, clientTimeStamp); TableName physicalTableName = SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES, configuration); Table statsWriterTable = conn.getQueryServices().getTable(physicalTableName.getName()); Table statsReaderTable = conn.getQueryServices().getTable(physicalTableName.getName()); StatisticsWriter statsTable = new StatisticsWriter(statsReaderTable, statsWriterTable, tableName, newClientTimeStamp); return statsTable; }
Example 5
Source File: FlappingLocalIndexIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testBuildIndexWhenUserTableAlreadyHasData() throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); String indexTableName = schemaName + "." + indexName; TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); String indexPhysicalTableName = physicalTableName.getNameAsString(); createBaseTable(tableName, null, "('e','i','o')"); Connection conn1 = DriverManager.getConnection(getUrl()); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('b',1,2,4,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('f',1,2,3,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('j',2,4,2,'a')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('q',3,1,1,'c')"); conn1.commit(); conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + indexTableName); assertTrue(rs.next()); assertEquals(4, rs.getInt(1)); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); org.apache.hadoop.hbase.client.Connection hbaseConn = admin.getConnection(); Table indexTable = hbaseConn.getTable(TableName.valueOf(indexPhysicalTableName)); Pair<byte[][], byte[][]> startEndKeys = hbaseConn.getRegionLocator(TableName.valueOf(indexPhysicalTableName)).getStartEndKeys(); byte[][] startKeys = startEndKeys.getFirst(); byte[][] endKeys = startEndKeys.getSecond(); for (int i = 0; i < startKeys.length; i++) { Scan s = new Scan(); s.addFamily(QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES); s.setStartRow(startKeys[i]); s.setStopRow(endKeys[i]); ResultScanner scanner = indexTable.getScanner(s); int count = 0; for(Result r:scanner){ count++; } scanner.close(); assertEquals(1, count); } indexTable.close(); }
Example 6
Source File: FlappingLocalIndexIT.java From phoenix with Apache License 2.0 | 5 votes |
private void testBuildingLocalIndexShouldHandleNoSuchColumnFamilyException(boolean coveredIndex) throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); String indexTableName = schemaName + "." + indexName; TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); createBaseTable(tableName, null, null, coveredIndex ? "cf" : null); Connection conn1 = DriverManager.getConnection(getUrl()); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('b',1,2,4,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('f',1,2,3,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('j',2,4,2,'a')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('q',3,1,1,'c')"); conn1.commit(); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); TableDescriptor tableDescriptor = admin.getDescriptor(physicalTableName); tableDescriptor=TableDescriptorBuilder.newBuilder(tableDescriptor).addCoprocessor(DeleyOpenRegionObserver.class.getName(), null, QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY - 1, null).build(); admin.disableTable(physicalTableName); admin.modifyTable(tableDescriptor); admin.enableTable(physicalTableName); DeleyOpenRegionObserver.DELAY_OPEN = true; conn1.createStatement().execute( "CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(k3)" + (coveredIndex ? " include(cf.v1)" : "")); DeleyOpenRegionObserver.DELAY_OPEN = false; ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + indexTableName); assertTrue(rs.next()); assertEquals(4, rs.getInt(1)); }
Example 7
Source File: LocalIndexIT.java From phoenix with Apache License 2.0 | 5 votes |
@Test public void testUseUncoveredLocalIndexWithSplitPrefix() throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); String indexPhysicalTableName = physicalTableName.getNameAsString(); Connection conn = getConnection(); conn.setAutoCommit(true); if (isNamespaceMapped) { conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName); } conn.createStatement().execute("CREATE TABLE " + tableName + " (pk1 INTEGER NOT NULL, pk2 INTEGER NOT NULL, pk3 INTEGER NOT NULL, v1 FLOAT, v2 FLOAT, V3 INTEGER CONSTRAINT pk PRIMARY KEY(pk1,pk2,pk3)) SALT_BUCKETS=16"); // + " (pk1 INTEGER NOT NULL, pk2 INTEGER NOT NULL, pk3 INTEGER NOT NULL, v1 FLOAT, v2 FLOAT, V3 INTEGER CONSTRAINT pk PRIMARY KEY(pk1,pk2,pk3))"); conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(pk1,pk3)"); // 1. Still use the index ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT pk1, pk2, pk3, v1 FROM " + tableName + " WHERE pk1 = 2 AND pk3 = 3"); assertEquals( "CLIENT PARALLEL 16-WAY RANGE SCAN OVER " + indexPhysicalTableName + " [1,2,3]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs.close(); }
Example 8
Source File: LocalIndexIT.java From phoenix with Apache License 2.0 | 4 votes |
@Test public void testUseUncoveredLocalIndexWithPrefix() throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); String indexPhysicalTableName = physicalTableName.getNameAsString(); Connection conn = getConnection(); conn.setAutoCommit(true); if (isNamespaceMapped) { conn.createStatement().execute("CREATE SCHEMA IF NOT EXISTS " + schemaName); } conn.createStatement().execute("CREATE TABLE " + tableName + " (pk1 INTEGER NOT NULL, pk2 INTEGER NOT NULL, pk3 INTEGER NOT NULL, v1 FLOAT, v2 FLOAT, V3 INTEGER CONSTRAINT pk PRIMARY KEY(pk1,pk2,pk3))"); conn.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(pk1,pk2,v1,v2)"); // 1. same prefix length, no other restrictions, but v3 is in the SELECT. Use the main table. ResultSet rs = conn.createStatement().executeQuery("EXPLAIN SELECT * FROM " + tableName + " WHERE pk1 = 3 AND pk2 = 4"); assertEquals( "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + physicalTableName + " [3,4]", QueryUtil.getExplainPlan(rs)); rs.close(); // 2. same prefix length, no other restrictions. Only index columns used. Use the index. rs = conn.createStatement().executeQuery("EXPLAIN SELECT v2 FROM " + tableName + " WHERE pk1 = 3 AND pk2 = 4"); assertEquals( "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + indexPhysicalTableName + " [1,3,4]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs.close(); // 3. same prefix length, but there's a column not on the index rs = conn.createStatement().executeQuery("EXPLAIN SELECT v2 FROM " + tableName + " WHERE pk1 = 3 AND pk2 = 4 AND v3 = 1"); assertEquals( "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + physicalTableName + " [3,4]\n" + " SERVER FILTER BY V3 = 1", QueryUtil.getExplainPlan(rs)); rs.close(); // 4. Longer prefix on the index, use it. rs = conn.createStatement().executeQuery("EXPLAIN SELECT v2 FROM " + tableName + " WHERE pk1 = 3 AND pk2 = 4 AND v1 = 3 AND v3 = 1"); assertEquals( "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + physicalTableName + " [1,3,4,3]\n" + " SERVER FILTER BY FIRST KEY ONLY AND \"V3\" = 1\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs.close(); }
Example 9
Source File: LocalIndexIT.java From phoenix with Apache License 2.0 | 4 votes |
@Test public void testPutsToLocalIndexTable() throws Exception { String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); String indexTableName = schemaName + "." + indexName; TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped); String indexPhysicalTableName = physicalTableName.getNameAsString(); createBaseTable(tableName, null, "('e','i','o')"); Connection conn1 = getConnection(); conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('b',1,2,4,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('f',1,2,3,'z')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('j',2,4,2,'a')"); conn1.createStatement().execute("UPSERT INTO "+tableName+" values('q',3,1,1,'c')"); conn1.commit(); ResultSet rs = conn1.createStatement().executeQuery("SELECT COUNT(*) FROM " + indexTableName); assertTrue(rs.next()); assertEquals(4, rs.getInt(1)); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); Table indexTable = admin.getConnection().getTable(TableName.valueOf(indexPhysicalTableName)); Pair<byte[][], byte[][]> startEndKeys = admin.getConnection().getRegionLocator(TableName.valueOf(indexPhysicalTableName)) .getStartEndKeys(); byte[][] startKeys = startEndKeys.getFirst(); byte[][] endKeys = startEndKeys.getSecond(); for (int i = 0; i < startKeys.length; i++) { Scan s = new Scan(); s.addFamily(QueryConstants.DEFAULT_LOCAL_INDEX_COLUMN_FAMILY_BYTES); s.setStartRow(startKeys[i]); s.setStopRow(endKeys[i]); ResultScanner scanner = indexTable.getScanner(s); int count = 0; for(Result r:scanner){ count++; } scanner.close(); assertEquals(1, count); } indexTable.close(); }
Example 10
Source File: LocalIndexSplitMergeIT.java From phoenix with Apache License 2.0 | 4 votes |
@Test public void testLocalIndexScanAfterRegionSplit() throws Exception { String schemaName = generateUniqueName(); String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false); String indexPhysicalTableName = physicalTableName.getNameAsString(); createBaseTable(tableName, "('e','j','o')"); Connection conn1 = getConnectionForLocalIndexTest(); try { String[] strings = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; for (int i = 0; i < 26; i++) { conn1.createStatement() .execute("UPSERT INTO " + tableName + " values('" + strings[i] + "'," + i + "," + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')"); } conn1.commit(); conn1.createStatement() .execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); conn1.createStatement() .execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)"); ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName); assertTrue(rs.next()); Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); for (int i = 1; i < 3; i++) { admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3 * i]))); List<RegionInfo> regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); while (regionsOfUserTable.size() != (4 + i)) { Thread.sleep(100); regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); } assertEquals(4 + i, regionsOfUserTable.size()); String[] tIdColumnValues = new String[26]; String[] v1ColumnValues = new String[26]; int[] k1ColumnValue = new int[26]; String query = "SELECT t_id,k1,v1 FROM " + tableName; rs = conn1.createStatement().executeQuery(query); Thread.sleep(1000); for (int j = 0; j < 26; j++) { assertTrue("No row found at " + j, rs.next()); tIdColumnValues[j] = rs.getString("t_id"); k1ColumnValue[j] = rs.getInt("k1"); v1ColumnValues[j] = rs.getString("V1"); } Arrays.sort(tIdColumnValues); Arrays.sort(v1ColumnValues); Arrays.sort(k1ColumnValue); assertTrue(Arrays.equals(strings, tIdColumnValues)); assertTrue(Arrays.equals(strings, v1ColumnValues)); for (int m = 0; m < 26; m++) { assertEquals(m, k1ColumnValue[m]); } rs = conn1.createStatement().executeQuery("EXPLAIN " + query); assertEquals("CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER " + indexPhysicalTableName + " [1]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); query = "SELECT t_id,k1,k3 FROM " + tableName; rs = conn1.createStatement().executeQuery("EXPLAIN " + query); assertEquals( "CLIENT PARALLEL " + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1)) + "-WAY RANGE SCAN OVER " + indexPhysicalTableName + " [2]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs = conn1.createStatement().executeQuery(query); Thread.sleep(1000); int[] k3ColumnValue = new int[26]; for (int j = 0; j < 26; j++) { assertTrue(rs.next()); tIdColumnValues[j] = rs.getString("t_id"); k1ColumnValue[j] = rs.getInt("k1"); k3ColumnValue[j] = rs.getInt("k3"); } Arrays.sort(tIdColumnValues); Arrays.sort(k1ColumnValue); Arrays.sort(k3ColumnValue); assertTrue(Arrays.equals(strings, tIdColumnValues)); for (int m = 0; m < 26; m++) { assertEquals(m, k1ColumnValue[m]); assertEquals(m + 2, k3ColumnValue[m]); } } } finally { conn1.close(); } }
Example 11
Source File: LocalIndexSplitMergeIT.java From phoenix with Apache License 2.0 | 4 votes |
@Test public void testLocalIndexScanAfterRegionsMerge() throws Exception { String schemaName = generateUniqueName(); String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false); String indexPhysicalTableName = physicalTableName.getNameAsString(); createBaseTable(tableName, "('e','j','o')"); Connection conn1 = getConnectionForLocalIndexTest(); try { String[] strings = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; for (int i = 0; i < 26; i++) { conn1.createStatement() .execute("UPSERT INTO " + tableName + " values('" + strings[i] + "'," + i + "," + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')"); } conn1.commit(); conn1.createStatement() .execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); conn1.createStatement() .execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)"); ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName); assertTrue(rs.next()); Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); List<RegionInfo> regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); admin.mergeRegionsAsync(regionsOfUserTable.get(0).getEncodedNameAsBytes(), regionsOfUserTable.get(1).getEncodedNameAsBytes(), false); regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); while (regionsOfUserTable.size() != 3) { Thread.sleep(100); regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); } String query = "SELECT t_id,k1,v1 FROM " + tableName; rs = conn1.createStatement().executeQuery(query); Thread.sleep(1000); for (int j = 0; j < 26; j++) { assertTrue(rs.next()); assertEquals(strings[25 - j], rs.getString("t_id")); assertEquals(25 - j, rs.getInt("k1")); assertEquals(strings[j], rs.getString("V1")); } rs = conn1.createStatement().executeQuery("EXPLAIN " + query); assertEquals( "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER " + indexPhysicalTableName + " [1]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); query = "SELECT t_id,k1,k3 FROM " + tableName; rs = conn1.createStatement().executeQuery("EXPLAIN " + query); assertEquals( "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER " + indexPhysicalTableName + " [2]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs)); rs = conn1.createStatement().executeQuery(query); Thread.sleep(1000); for (int j = 0; j < 26; j++) { assertTrue(rs.next()); assertEquals(strings[j], rs.getString("t_id")); assertEquals(j, rs.getInt("k1")); assertEquals(j + 2, rs.getInt("k3")); } } finally { conn1.close(); } }
Example 12
Source File: LocalIndexSplitMergeIT.java From phoenix with Apache License 2.0 | 4 votes |
@Test public void testLocalIndexScanWithMergeSpecialCase() throws Exception { String schemaName = generateUniqueName(); String tableName = schemaName + "." + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false); createBaseTable(tableName, "('a','aaaab','def')"); Connection conn1 = getConnectionForLocalIndexTest(); try { String[] strings = { "aa", "aaa", "aaaa", "bb", "cc", "dd", "dff", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; for (int i = 0; i < 26; i++) { conn1.createStatement() .execute("UPSERT INTO " + tableName + " values('" + strings[i] + "'," + i + "," + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')"); } conn1.commit(); conn1.createStatement() .execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)"); conn1.createStatement() .execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)"); Admin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin(); List<RegionInfo> regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); admin.mergeRegionsAsync(regionsOfUserTable.get(0).getEncodedNameAsBytes(), regionsOfUserTable.get(1).getEncodedNameAsBytes(), false); regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); while (regionsOfUserTable.size() != 3) { Thread.sleep(100); regionsOfUserTable = MetaTableAccessor.getTableRegions(admin.getConnection(), physicalTableName, false); } String query = "SELECT t_id,k1,v1 FROM " + tableName; ResultSet rs = conn1.createStatement().executeQuery(query); for (int j = 0; j < 26; j++) { assertTrue(rs.next()); assertEquals(strings[25-j], rs.getString("t_id")); assertEquals(25-j, rs.getInt("k1")); assertEquals(strings[j], rs.getString("V1")); } query = "SELECT t_id,k1,k3 FROM " + tableName; rs = conn1.createStatement().executeQuery(query); for (int j = 0; j < 26; j++) { assertTrue(rs.next()); assertEquals(strings[j], rs.getString("t_id")); assertEquals(j, rs.getInt("k1")); assertEquals(j + 2, rs.getInt("k3")); } } finally { conn1.close(); } }