org.apache.phoenix.util.PropertiesUtil Java Examples
The following examples show how to use
org.apache.phoenix.util.PropertiesUtil.
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: ClientTimeArithmeticQueryIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testSmallIntSubtractionExpression() throws Exception { String query = "SELECT entity_id FROM aTable where a_short - 129 = 0"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); assertEquals(rs.getString(1), ROW2); assertFalse(rs.next()); } finally { conn.close(); } }
Example #2
Source File: UpsertSelectOverlappingBatchesIT.java From phoenix with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { SlowBatchRegionObserver.SLOW_MUTATE = false; props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.put(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); dataTable = generateUniqueName(); index = "IDX_" + dataTable; try (Connection conn = driver.connect(url, props)) { conn.createStatement().execute("CREATE TABLE " + dataTable + " (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)"); // create the index and ensure its empty as well conn.createStatement().execute("CREATE INDEX " + index + " ON " + dataTable + " (v1)"); PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + dataTable + " VALUES(?,?,?)"); conn.setAutoCommit(false); for (int i = 0; i < 100; i++) { stmt.setInt(1, i); stmt.setString(2, "v1" + i); stmt.setString(3, "v2" + i); stmt.execute(); } conn.commit(); } }
Example #3
Source File: VariableLengthPKIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testToCharOnDate() throws Exception { long ts = nextTimestamp(); initPtsdbTableValues(ts); String query = "SELECT HOST,TO_CHAR(DATE) FROM PTSDB WHERE INST='x' AND HOST='y'"; String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(DateUtil.DEFAULT_DATE_FORMATTER.format(D1), rs.getString(2)); } finally { conn.close(); } }
Example #4
Source File: WhereCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testNotBetweenFilter() throws SQLException { String tenantId = "000000000000001"; String query = "select * from atable where organization_id='" + tenantId + "' and a_integer not between 0 and 10"; PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class); PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query); QueryPlan plan = pstmt.optimizeQuery(); Scan scan = plan.getContext().getScan(); Filter filter = scan.getFilter(); assertEquals( singleKVFilter(not(and( constantComparison( CompareOp.GREATER_OR_EQUAL, A_INTEGER, 0), constantComparison( CompareOp.LESS_OR_EQUAL, A_INTEGER, 10)))).toString(), filter.toString()); }
Example #5
Source File: SetPropertyIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testSpecifyingColumnFamilyForPhoenixTablePropertyFails() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); String ddl = "CREATE TABLE " + dataTableFullName + " (\n" +"ID1 VARCHAR(15) NOT NULL,\n" +"ID2 VARCHAR(15) NOT NULL,\n" +"CREATED_DATE DATE,\n" +"CREATION_TIME BIGINT,\n" +"LAST_USED DATE,\n" +"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) " + generateDDLOptions("SALT_BUCKETS = 8"); Connection conn1 = DriverManager.getConnection(getUrl(), props); conn1.createStatement().execute(ddl); ddl = "ALTER TABLE " + dataTableFullName + " SET CF.DISABLE_WAL = TRUE"; try { conn1.createStatement().execute(ddl); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.COLUMN_FAMILY_NOT_ALLOWED_TABLE_PROPERTY.getErrorCode(), e.getErrorCode()); } }
Example #6
Source File: ArrayIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testWithOutOfRangeIndex() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2); initTablesWithArrays(tenantId, null, ts, false, getUrl()); String query = "SELECT a_double_array[100] FROM table_with_array"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); PhoenixArray resultArray = (PhoenixArray) rs.getArray(1); assertNull(resultArray); } finally { conn.close(); } }
Example #7
Source File: CaseStatementIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testNonNullMultiCondCaseStatement() throws Exception { String query = "SELECT CASE WHEN entity_id = '000000000000000' THEN 1 WHEN entity_id = '000000000000001' THEN 2 ELSE 3 END FROM " + tableName + " WHERE organization_id=?"; String url = getUrl(); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); ResultSet rs = statement.executeQuery(); ResultSetMetaData rsm = rs.getMetaData(); assertEquals(ResultSetMetaData.columnNoNulls,rsm.isNullable(1)); } finally { conn.close(); } }
Example #8
Source File: VariableLengthPKIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testSkipScan() throws Exception { long ts = nextTimestamp(); String query = "SELECT HOST FROM PTSDB WHERE INST='abc' AND DATE>=TO_DATE('1970-01-01 00:00:00') AND DATE <TO_DATE('2171-01-01 00:00:00')"; String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { initTableValues(null, ts); PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals("abc-def-ghi", rs.getString(1)); assertFalse(rs.next()); } finally { conn.close(); } }
Example #9
Source File: DynamicFamilyIT.java From phoenix with Apache License 2.0 | 6 votes |
/** * Since dynamic columns are not in double quotes, the column name is not normalized, but instead * is left as is. This should succeed, since the user ID case is matched */ // FIXME @Test public void testGetCaseSensitiveDynCol() throws Exception { String query = "SELECT B.* FROM WEB_STATS(" + "B.\"" + LAST_LOGIN_TIME_PREFIX + USER_ID2 + "\"" + " TIME," + "B.\"" + LAST_LOGIN_TIME_PREFIX + USER_ID3 + "\"" + " TIME) WHERE entry='entry2'"; String url = getUrl() + ";"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(ENTRY2_USER_ID2_LOGIN_TIME, getLastLoginTimeValue(rs, USER_ID2)); assertEquals(ENTRY2_USER_ID3_LOGIN_TIME, getLastLoginTimeValue(rs, USER_ID3)); assertEquals(null, getLastLoginTimeValue(rs, Bytes.toString(USER_ID1_BYTES))); assertFalse(rs.next()); } finally { conn.close(); } }
Example #10
Source File: Array2IT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testVariableLengthArrayWithNullValue() throws Exception { String tenantId = getOrganizationId(); String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null); initTablesWithArrays(table, tenantId, null, true, getUrl()); String query = "SELECT a_string_array[2] FROM " + table; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); String[] strArr = new String[1]; strArr[0] = "XYZWER"; String result = rs.getString(1); assertNull(result); } finally { conn.close(); } }
Example #11
Source File: DistinctCountIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testDistinctCountOneWithEmptyResult() throws Exception { String tenantId = getOrganizationId(); String tableName = generateUniqueName(); initATableValues(null, null, getDefaultSplits(tenantId), null, tableName); String query = "SELECT count(DISTINCT 1) FROM "+tableName; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); assertFalse(rs.next()); } finally { conn.close(); } }
Example #12
Source File: NotQueryIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testNotEqualsByUnsignedFloat() throws Exception { String query = "SELECT a_unsigned_float -- and here comment\n" + "FROM aTable WHERE organization_id=? and a_unsigned_float != 0.01d and a_unsigned_float <= 0.02d"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); assertTrue(Floats.compare(rs.getFloat(1), 0.02f) == 0); assertFalse(rs.next()); } finally { conn.close(); } }
Example #13
Source File: TenantSpecificTablesDMLIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testUpsertValuesOnlyUpsertsTenantData() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(PHOENIX_JDBC_TENANT_SPECIFIC_URL, props); try { int count = conn.createStatement().executeUpdate("upsert into " + TENANT_TABLE_NAME + " (id, \"user\") values (1, 'Bon Scott')"); conn.commit(); assertEquals("Expected 1 row to have been inserted", 1, count); ResultSet rs = conn.createStatement().executeQuery("select count(*) from " + TENANT_TABLE_NAME); rs.next(); assertEquals(1, rs.getInt(1)); } finally { conn.close(); } }
Example #14
Source File: ProductMetricsIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testKeyOrderedAggregation1() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); String query = "SELECT date, sum(UNIQUE_USERS) FROM PRODUCT_METRICS WHERE date > to_date(?) GROUP BY organization_id, date"; String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { initTableValues(tenantId, getSplits(tenantId), ts); PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, DS4); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(D5, rs.getDate(1)); assertEquals(50, rs.getInt(2)); assertTrue(rs.next()); assertEquals(D6, rs.getDate(1)); assertEquals(60, rs.getInt(2)); assertFalse(rs.next()); } finally { conn.close(); } }
Example #15
Source File: ViewCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
public void assertViewType(String[] viewNames, String[] viewDDLs, ViewType viewType) throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); PhoenixConnection conn = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class); String ct = "CREATE TABLE t (k1 INTEGER NOT NULL, k2 VARCHAR, v VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2))"; conn.createStatement().execute(ct); for (String viewDDL : viewDDLs) { conn.createStatement().execute(viewDDL); } StringBuilder buf = new StringBuilder(); int count = 0; for (String view : viewNames) { PTable table = conn.getTable(new PTableKey(null, view)); assertEquals(viewType, table.getViewType()); conn.createStatement().execute("DROP VIEW " + table.getName().getString()); buf.append(' '); buf.append(table.getName().getString()); count++; } assertEquals("Expected " + viewDDLs.length + ", but got " + count + ":"+ buf.toString(), viewDDLs.length, count); }
Example #16
Source File: SortMergeJoinNoSpoolingIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testJoinWithMemoryLimit() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.put(QueryServices.CLIENT_SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(1)); try (Connection conn = DriverManager.getConnection(getUrl(), props)) { String tableName1 = getTableName(conn, JOIN_ITEM_TABLE_FULL_NAME); String tableName2 = getTableName(conn, JOIN_SUPPLIER_TABLE_FULL_NAME); String query = "SELECT /*+ USE_SORT_MERGE_JOIN*/ item.\"item_id\", item.name, supp.\"supplier_id\", supp.name FROM " + tableName1 + " item JOIN " + tableName2 + " supp ON item.\"supplier_id\" = supp.\"supplier_id\" ORDER BY \"item_id\""; PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); try { rs.next(); fail("Expected PhoenixIOException due to IllegalStateException"); } catch (PhoenixIOException e) { assertThat(e.getMessage(), containsString( "Queue full. Consider increasing memory threshold or spooling to disk")); } } }
Example #17
Source File: QueryIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testMixedTypeInListStatement() throws Exception { String query = "SELECT entity_id FROM ATABLE WHERE organization_id=? AND x_long IN (5, ?)"; String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); long l = Integer.MAX_VALUE + 1L; statement.setLong(2, l); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(ROW7, rs.getString(1)); assertTrue(rs.next()); assertEquals(ROW9, rs.getString(1)); assertFalse(rs.next()); } finally { conn.close(); } }
Example #18
Source File: ParallelIteratorsSplitTest.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testGetSplitsWithSkipScanFilter() throws Exception { byte[][] splits = new byte[][] {Ka1A, Ka1B, Ka1E, Ka1G, Ka1I, Ka2A}; createTestTable(getUrl(),DDL,splits, null); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); PTable table = pconn.getMetaDataCache().getTable(new PTableKey(pconn.getTenantId(), TABLE_NAME)); TableRef tableRef = new TableRef(table); List<HRegionLocation> regions = pconn.getQueryServices().getAllTableRegions(tableRef.getTable().getPhysicalName().getBytes()); List<KeyRange> ranges = getSplits(tableRef, scan, regions, scanRanges); assertEquals("Unexpected number of splits: " + ranges.size(), expectedSplits.size(), ranges.size()); for (int i=0; i<expectedSplits.size(); i++) { assertEquals(expectedSplits.get(i), ranges.get(i)); } }
Example #19
Source File: PercentileIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testMultiplePercentRanksOnSelect() throws Exception { String tenantId = getOrganizationId(); String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC), PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM " + tableName; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); BigDecimal rank = rs.getBigDecimal(1); rank = rank.setScale(2, RoundingMode.HALF_UP); assertEquals(0.33, rank.doubleValue(), 0.0); rank = rs.getBigDecimal(2); rank = rank.setScale(2, RoundingMode.HALF_UP); assertEquals(0.11, rank.doubleValue(), 0.0); assertFalse(rs.next()); } finally { conn.close(); } }
Example #20
Source File: QueryCompilerTest.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testOrderByAggSelectNonAgg() throws Exception { try { // Order by in select with no limit or group by String query = "select a_string from ATABLE order by max(b_string)"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.executeQuery(); fail(); } finally { conn.close(); } } catch (SQLException e) { assertTrue(e.getMessage(), e.getMessage().contains("ERROR 1018 (42Y27): Aggregate may not contain columns not in GROUP BY. A_STRING")); } }
Example #21
Source File: PercentileIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testPercentRank() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts); String query = "SELECT PERCENT_RANK(5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at // timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); BigDecimal rank = rs.getBigDecimal(1); rank = rank.setScale(2, RoundingMode.HALF_UP); assertEquals(0.56, rank.doubleValue(), 0.0); assertFalse(rs.next()); } finally { conn.close(); } }
Example #22
Source File: QueryWithTableSampleIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testSingleQuery() throws Exception { Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { prepareTableWithValues(conn, 100); String query = "SELECT i1, i2 FROM " + tableName +" tablesample (45) "; ResultSet rs = conn.createStatement().executeQuery(query); assertTrue(rs.next()); assertEquals(2, rs.getInt(1)); assertEquals(200, rs.getInt(2)); assertTrue(rs.next()); assertEquals(6, rs.getInt(1)); assertEquals(600, rs.getInt(2)); } finally { conn.close(); } }
Example #23
Source File: ProductMetricsIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testDegenerateAggregation() throws Exception { String tablename=generateUniqueName(); String tenantId = getOrganizationId(); String query = "SELECT count(1), feature FROM "+tablename+" WHERE organization_id=? AND \"DATE\" >= to_date(?) AND \"DATE\" <= to_date(?) GROUP BY feature"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { initTableValues(tablename, tenantId, getSplits(tenantId)); PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); // Start date larger than end date statement.setString(2, DS4); statement.setString(3, DS2); ResultSet rs = statement.executeQuery(); assertFalse(rs.next()); } finally { conn.close(); } }
Example #24
Source File: PercentileIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testPercentRankDescOnDECIMALColumn() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts); String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC) FROM aTable"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at // timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); BigDecimal rank = rs.getBigDecimal(1); rank = rank.setScale(2, RoundingMode.HALF_UP); assertEquals(0.33, rank.doubleValue(), 0.0); assertFalse(rs.next()); } finally { conn.close(); } }
Example #25
Source File: IndexScrutinyToolForTenantIT.java From phoenix with Apache License 2.0 | 6 votes |
/** * Create the test data */ @Before public void setup() throws SQLException { tenantId = generateUniqueName(); tenantViewName = generateUniqueName(); indexNameTenant = generateUniqueName(); multiTenantTable = generateUniqueName(); viewIndexTableName = "_IDX_" + multiTenantTable; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); connGlobal = DriverManager.getConnection(getUrl(), props); props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); connTenant = DriverManager.getConnection(getUrl(), props); String createTblStr = "CREATE TABLE %s (COL1 VARCHAR(15) NOT NULL,ID INTEGER NOT NULL" + ", NAME VARCHAR, CONSTRAINT PK_1 PRIMARY KEY (COL1, ID)) MULTI_TENANT=true"; createTestTable(getUrl(), String.format(createTblStr, multiTenantTable)); connTenant.createStatement() .execute(String.format(createViewStr, tenantViewName, multiTenantTable)); String idxStmtTenant = String.format(createIndexStr, indexNameTenant, tenantViewName); connTenant.createStatement().execute(idxStmtTenant); connTenant.commit(); connGlobal.commit(); }
Example #26
Source File: VariableLengthPKIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testSingleFixedLengthNull() throws Exception { String bTableName = generateUniqueName(); String query = "SELECT C_INTEGER,COUNT(1) FROM "+bTableName+" GROUP BY C_INTEGER"; String url = getUrl(); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(url, props); try { initBTableValues(null,bTableName); PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(0, rs.getInt(1)); assertTrue(rs.wasNull()); assertEquals(2, rs.getLong(2)); assertTrue(rs.next()); assertEquals(1000, rs.getInt(1)); assertEquals(2, rs.getLong(2)); assertFalse(rs.next()); } finally { conn.close(); } }
Example #27
Source File: IndexMetadataIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testIndexGetsUpdateCacheFreqFromBaseTable() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); String testTable = generateUniqueName(); long updateCacheFreq = 10000; String ddl = "CREATE TABLE " + testTable + " (k varchar primary key, v1 varchar) " + "UPDATE_CACHE_FREQUENCY=" + updateCacheFreq; Statement stmt = conn.createStatement(); stmt.execute(ddl); String localIndex = "LOCAL_" + generateUniqueName(); String globalIndex = "GLOBAL_" + generateUniqueName(); ddl = "CREATE LOCAL INDEX " + localIndex + " ON " + testTable + " (v1) "; stmt.execute(ddl); ddl = "CREATE INDEX " + globalIndex + " ON " + testTable + " (v1) "; stmt.execute(ddl); // Check that local and global index both have the propagated UPDATE_CACHE_FREQUENCY value assertUpdateCacheFreq(conn, testTable, updateCacheFreq); assertUpdateCacheFreq(conn, localIndex, updateCacheFreq); assertUpdateCacheFreq(conn, globalIndex, updateCacheFreq); }
Example #28
Source File: DistinctCountIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testDistinctCountONEWithEmptyResult() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); initATableValues(null, null, getDefaultSplits(tenantId), null, ts); String query = "SELECT count(DISTINCT 1) FROM aTable"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at // timestamp 2 Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); assertFalse(rs.next()); } finally { conn.close(); } }
Example #29
Source File: NumericArithmeticIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testScanByUnsignedFloatValue() throws Exception { String query = "SELECT a_string, b_string, a_unsigned_float FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_float"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, getOrganizationId()); statement.setFloat(2, 0.01f); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); assertEquals(rs.getString(1), A_VALUE); assertEquals(rs.getString("B_string"), B_VALUE); assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0); assertFalse(rs.next()); } finally { conn.close(); } }
Example #30
Source File: QueryIT.java From phoenix with Apache License 2.0 | 6 votes |
@Test public void testColumnOnBothSides() throws Exception { String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_string = b_string"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); assertEquals(rs.getString(1), ROW7); assertFalse(rs.next()); } finally { conn.close(); } }