+ " SELECT NEXT VALUE FOR "+ tableName + "_seq, val FROM " + tableName); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); for (int i=0; i<12; i++) { try {
protected void testSplitDuringIndexScan(boolean isReverse) throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(QueryServices.SCAN_CACHE_SIZE_ATTRIB, Integer.toString(2)); props.setProperty(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.toString(false)); Connection conn1 = getConnection(props); String tableName = "TBL_" + generateUniqueName(); String indexName = "IDX_" + generateUniqueName(); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); 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"}; createTableAndLoadData(conn1, tableName, indexName, strings, isReverse); ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName); assertTrue(rs.next()); splitDuringScan(conn1, tableName, indexName, strings, admin, isReverse); } finally { if(conn1 != null) conn1.close(); if(admin != null) admin.close(); } }
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)); }
@Test public void testCreateTableColumnFamilyHBaseAttribs8() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) BLOOMFILTER = 'ROW', SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(BloomType.ROW, columnFamilies[0].getBloomFilterType()); }
ResultSet rs = conn1.createStatement().executeQuery("EXPLAIN "+ query); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); int numRegions = admin.getTableRegions(physicalTableName).size();
/** * Test that when the ddl only has PK cols, ttl is set. */ @Test public void testCreateTableColumnFamilyHBaseAttribs1() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) TTL=86400, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(1, columnFamilies.length); assertEquals(86400, columnFamilies[0].getTimeToLive()); }
/** * Synchronously split table at the given split point */ protected static void splitRegion(TableName fullTableName, byte[] splitPoint) throws SQLException, IOException, InterruptedException { Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); admin.split(fullTableName, splitPoint); // make sure the split finishes (there's no synchronous splitting before HBase 2.x) admin.disableTable(fullTableName); admin.enableTable(fullTableName); }
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));
/** * Tests that when: 1) DDL has both pk as well as key value columns 2) There is a default column * family specified. Then: 1)TTL is set for the specified default column family. */ @Test public void testCreateTableColumnFamilyHBaseAttribs6() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint," + " col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) DEFAULT_COLUMN_FAMILY='a', TTL=10000, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(1, columnFamilies.length); assertEquals("a", columnFamilies[0].getNameAsString()); assertEquals(10000, columnFamilies[0].getTimeToLive()); }
/** * Tests that when: 1) DDL has only pk columns 2) There is a default column family specified. * Then: 1)TTL is set for the specified default column family. */ @Test public void testCreateTableColumnFamilyHBaseAttribs7() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) DEFAULT_COLUMN_FAMILY='a', TTL=10000, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(1, columnFamilies.length); assertEquals("a", columnFamilies[0].getNameAsString()); assertEquals(10000, columnFamilies[0].getTimeToLive()); }
@Test public void testMappedView() throws Exception { Properties props = new Properties(); String schema = generateUniqueName(); String tableName = generateUniqueName(); String fullTablename = schema + QueryConstants.NAME_SEPARATOR + tableName; props.setProperty(QueryServices.SCHEMA_ATTRIB, schema); Connection conn = DriverManager.getConnection(getUrl(), props); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); admin.createNamespace(NamespaceDescriptor.create(schema).build()); admin.createTable(TableDescriptorBuilder.newBuilder(TableName.valueOf(fullTablename)). addColumnFamily(ColumnFamilyDescriptorBuilder.of(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES)).build()); Put put = new Put(PVarchar.INSTANCE.toBytes(fullTablename)); put.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, QueryConstants.EMPTY_COLUMN_BYTES, QueryConstants.EMPTY_COLUMN_VALUE_BYTES); Table phoenixSchematable = admin.getConnection().getTable(TableName.valueOf(fullTablename)); phoenixSchematable.put(put); phoenixSchematable.close(); conn.createStatement().execute("CREATE VIEW " + tableName + " (tablename VARCHAR PRIMARY KEY)"); ResultSet rs = conn.createStatement().executeQuery("select tablename from " + tableName); assertTrue(rs.next()); assertEquals(fullTablename, rs.getString(1)); admin.close(); conn.close(); } }
@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()); } } } }
/** * Disable and drop all the tables except SYSTEM.CATALOG and SYSTEM.SEQUENCE */ private static void disableAndDropNonSystemTables() throws Exception { if (driver == null) return; Admin admin = driver.getConnectionQueryServices(null, null).getAdmin(); try { TableDescriptor[] tables = admin.listTables(); for (TableDescriptor table : tables) { String schemaName = SchemaUtil.getSchemaNameFromFullName(table.getTableName().getName()); if (!QueryConstants.SYSTEM_SCHEMA_NAME.equals(schemaName)) { disableAndDropTable(admin, table.getTableName()); } } } finally { admin.close(); } }
/** * Tests that when: 1) DDL has both pk as well as key value columns 2) Key value columns have * different column family names 3) TTL specifier doesn't have column family name. Then: 1)TTL * is set. 2)All column families have the same TTL. */ @Test public void testCreateTableColumnFamilyHBaseAttribs2() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " c.col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) TTL=86400, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(2, columnFamilies.length); assertEquals(86400, columnFamilies[0].getTimeToLive()); assertEquals("B", columnFamilies[0].getNameAsString()); assertEquals(86400, columnFamilies[1].getTimeToLive()); assertEquals("C", columnFamilies[1].getNameAsString()); }
/** * Tests that when: 1) DDL has both pk as well as key value columns 2) Key value columns have * both default and explicit column family names 3) TTL specifier doesn't have column family * name. Then: 1)TTL is set. 2)All column families have the same TTL. */ @Test public void testCreateTableColumnFamilyHBaseAttribs3() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) TTL=86400, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(2, columnFamilies.length); assertEquals("0", columnFamilies[0].getNameAsString()); assertEquals(86400, columnFamilies[0].getTimeToLive()); assertEquals("B", columnFamilies[1].getNameAsString()); assertEquals(86400, columnFamilies[1].getTimeToLive()); }
/** * Tests that when: 1) DDL has both pk as well as key value columns 2) Key value columns have * explicit column family names 3) Different BLOCKSIZE specifiers for different column * family names. Then: 1)BLOCKSIZE is set. 2)Each explicit column family has the * BLOCKSIZE as specified in DDL. */ @Test public void testCreateTableColumnFamilyHBaseAttribs5() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " c.col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) b.BLOCKSIZE=50000, c.BLOCKSIZE=60000, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(2, columnFamilies.length); assertEquals("B", columnFamilies[0].getNameAsString()); assertEquals(50000, columnFamilies[0].getBlocksize()); assertEquals("C", columnFamilies[1].getNameAsString()); assertEquals(60000, columnFamilies[1].getBlocksize()); }
/** * Tests that when: 1) DDL has both pk as well as key value columns 2) Key value columns have * both default and explicit column family names 3) Block size specifier has the explicit * column family name. Then: 1)BLOCKSIZE is set. 2)The default column family has * DEFAULT_BLOCKSIZE. 3)The explicit column family has the BLOCK_SIZE specified * in DDL. */ @Test public void testCreateTableColumnFamilyHBaseAttribs4() throws Exception { String tableName = generateUniqueName(); String ddl = "create table IF NOT EXISTS " + tableName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " b.col2 bigint," + " col3 bigint, " + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1)" + " ) b.BLOCKSIZE=50000, SALT_BUCKETS = 4"; Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(ddl); Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); ColumnFamilyDescriptor[] columnFamilies = admin.getDescriptor(TableName.valueOf(tableName)).getColumnFamilies(); assertEquals(2, columnFamilies.length); assertEquals("0", columnFamilies[0].getNameAsString()); assertEquals(ColumnFamilyDescriptorBuilder.DEFAULT_BLOCKSIZE, columnFamilies[0].getBlocksize()); assertEquals("B", columnFamilies[1].getNameAsString()); assertEquals(50000, columnFamilies[1].getBlocksize()); }
/** * Ensures each region of SYSTEM.CATALOG is on a different region server */ private static void moveRegion(HRegionInfo regionInfo, ServerName srcServerName, ServerName dstServerName) throws Exception { Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); HBaseTestingUtility util = getUtility(); MiniHBaseCluster cluster = util.getHBaseCluster(); HMaster master = cluster.getMaster(); AssignmentManager am = master.getAssignmentManager(); HRegionServer dstServer = util.getHBaseCluster().getRegionServer(dstServerName); HRegionServer srcServer = util.getHBaseCluster().getRegionServer(srcServerName); byte[] encodedRegionNameInBytes = regionInfo.getEncodedNameAsBytes(); admin.move(encodedRegionNameInBytes, Bytes.toBytes(dstServer.getServerName().getServerName())); while (dstServer.getOnlineRegion(regionInfo.getRegionName()) == null || dstServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes) || srcServer.getRegionsInTransitionInRS().containsKey(encodedRegionNameInBytes)) { // wait for the move to be finished Thread.sleep(100); } } }
@SuppressWarnings("deprecation") private static void initTableValues() throws Exception { ConnectionQueryServices services = driver.getConnectionQueryServices(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)); Table hTable = services.getTable(SchemaUtil.getTableNameAsBytes(WEB_STATS_SCHEMA_NAME,WEB_STATS)); try {
@Test public void testCreateTable () throws Exception { String tableName = generateUniqueName(); String ddl = "CREATE TABLE " + tableName + " " + " (flume_time timestamp not null, col1 varchar , col2 varchar" + " CONSTRAINT pk PRIMARY KEY (flume_time))\n"; final String fullTableName = tableName; sinkContext = new Context (); sinkContext.put(FlumeConstants.CONFIG_TABLE, fullTableName); sinkContext.put(FlumeConstants.CONFIG_JDBC_URL, getUrl()); sinkContext.put(FlumeConstants.CONFIG_SERIALIZER,EventSerializers.REGEX.name()); sinkContext.put(FlumeConstants.CONFIG_TABLE_DDL, ddl); sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_REGULAR_EXPRESSION,"^([^\t]+)\t([^\t]+)$"); sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_COLUMN_NAMES,"col1,col2"); sinkContext.put(FlumeConstants.CONFIG_SERIALIZER_PREFIX + FlumeConstants.CONFIG_ROWKEY_TYPE_GENERATOR, DefaultKeyGenerator.TIMESTAMP.name()); sink = new PhoenixSink(); Configurables.configure(sink, sinkContext); Assert.assertEquals(LifecycleState.IDLE, sink.getLifecycleState()); final Channel channel = this.initChannel(); sink.setChannel(channel); sink.start(); Admin admin = driver.getConnectionQueryServices(getUrl(), TestUtil.TEST_PROPERTIES).getAdmin(); try { boolean exists = admin.tableExists(TableName.valueOf(fullTableName)); Assert.assertTrue(exists); }finally { admin.close(); } }