Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1k
PHOENIX-5259 Phoenix Salted Table Secondary Indexes Come Salted#589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yanxinyi
wants to merge
1
commit into
apache:masterChoose a base branch
from
yanxinyi:PHOENIX-5259
base:master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Uh oh!
There was an error while loading. Please reload this page.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121 phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexSaltingIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| package org.apache.phoenix.end2end; | ||
| import org.apache.phoenix.end2end.index.BaseLocalIndexIT; | ||
| import org.apache.phoenix.exception.SQLExceptionCode; | ||
| import org.apache.phoenix.util.PropertiesUtil; | ||
| import org.junit.Test; | ||
| import java.sql.Connection; | ||
| import java.sql.DriverManager; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.util.Properties; | ||
| import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
| public class IndexSaltingIT extends BaseLocalIndexIT { | ||
| public IndexSaltingIT(boolean isNamespaceMapped) { | ||
| super(isNamespaceMapped); | ||
| } | ||
| private String createTable = "CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, " + | ||
| "NAME VARCHAR, ZIP INTEGER) "; | ||
| private String createIndexTable = "CREATE INDEX %s ON %s (ZIP) INCLUDE(NAME) "; | ||
| private String selectQuery = "SELECT SALT_BUCKETS FROM SYSTEM.CATALOG " + | ||
| "WHERE TABLE_NAME = '%s' AND TABLE_TYPE = 'i'"; | ||
| @Test | ||
| public void testSecondaryIndexWithSaltingOptionOnBaseTable() throws Exception { | ||
| String dataTableName = generateUniqueName(); | ||
| String indexTableName = generateUniqueName(); | ||
| String indexTableWithSaltingName = generateUniqueName(); | ||
| String localIndexTableWithSaltingName = generateUniqueName(); | ||
| Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); | ||
| Connection conn = DriverManager.getConnection(getUrl(), props); | ||
| try { | ||
| String stmString1 = String.format(createTable + "SALT_BUCKETS=10", dataTableName); | ||
| conn.createStatement().execute(stmString1); | ||
| conn.commit(); | ||
| // create index table without salting option should not be salted | ||
| String stmtString2 = String.format(createIndexTable, indexTableName, dataTableName); | ||
| conn.createStatement().execute(stmtString2); | ||
| conn.commit(); | ||
| String stmtString3 = String.format(selectQuery, indexTableName); | ||
| ResultSet rs = conn.createStatement().executeQuery(stmtString3); | ||
| assertTrue(rs.next()); | ||
| assertEquals(null, rs.getString(1)); | ||
| assertFalse(rs.next()); | ||
| // testing index with diff salting value | ||
| String stmtString4 = String.format(createIndexTable + "SALT_BUCKETS=5", | ||
| indexTableWithSaltingName, dataTableName); | ||
| conn.createStatement().execute(stmtString4); | ||
| conn.commit(); | ||
| String stmtString5 = String.format(selectQuery, indexTableWithSaltingName); | ||
| rs = conn.createStatement().executeQuery(stmtString5); | ||
| assertTrue(rs.next()); | ||
| assertEquals(5, rs.getInt(1)); | ||
| assertFalse(rs.next()); | ||
| // local index should not have a salting option. | ||
| try { | ||
| String stmtString6 = String.format( | ||
| "CREATE LOCAL INDEX %s ON %s (ZIP) INCLUDE(NAME) SALT_BUCKETS=5", | ||
| localIndexTableWithSaltingName, dataTableName); | ||
| conn.createStatement().execute(stmtString6); | ||
| conn.commit(); | ||
| fail(); | ||
| } catch (SQLException e) { | ||
| assertEquals(SQLExceptionCode.CANNOT_SALT_LOCAL_INDEX.getErrorCode(), | ||
| e.getErrorCode()); | ||
| } | ||
| } finally { | ||
| conn.close(); | ||
| } | ||
| } | ||
| @Test | ||
| public void testSecondaryIndexWithoutSaltingOptionOnBaseTable() throws Exception { | ||
| String dataTableName = generateUniqueName(); | ||
| String indexTableName = generateUniqueName(); | ||
| String indexTableWithSaltingName = generateUniqueName(); | ||
| Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); | ||
| Connection conn = DriverManager.getConnection(getUrl(), props); | ||
| try { | ||
| String stmString1 = String.format(createTable, dataTableName); | ||
| conn.createStatement().execute(stmString1); | ||
| conn.commit(); | ||
| String stmtString2 = String.format(createIndexTable, indexTableName, dataTableName); | ||
| conn.createStatement().execute(stmtString2); | ||
| conn.commit(); | ||
| String stmtString3 = String.format(selectQuery, indexTableName); | ||
| ResultSet rs = conn.createStatement().executeQuery(stmtString3); | ||
| assertTrue(rs.next()); | ||
| assertEquals(null, rs.getString(1)); | ||
| assertFalse(rs.next()); | ||
| String stmtString4 = String.format(createIndexTable + "SALT_BUCKETS=5", | ||
| indexTableWithSaltingName, dataTableName); | ||
| conn.createStatement().execute(stmtString4); | ||
| conn.commit(); | ||
| String stmtString5 = String.format(selectQuery, indexTableWithSaltingName); | ||
| rs = conn.createStatement().executeQuery(stmtString5); | ||
| assertTrue(rs.next()); | ||
| assertEquals(5, rs.getInt(1)); | ||
| assertFalse(rs.next()); | ||
| } finally { | ||
| conn.close(); | ||
| } | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2 phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2069,7 +2069,7 @@ private PTable createTableInternal(CreateTableStatement statement, byte[][] spli | ||
| } | ||
| // Salt the index table if the data table is salted | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please update the comment to reflect the change. | ||
| if (saltBucketNum == null) { | ||
| if (parent != null) { | ||
| if (tableType != PTableType.INDEX && parent != null) { | ||
| saltBucketNum = parent.getBucketNum(); | ||
| } | ||
| } else if (saltBucketNum.intValue() == 0) { | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra space before '('