Java Code Examples for org.apache.phoenix.jdbc.PhoenixDriver

The following examples show how to use org.apache.phoenix.jdbc.PhoenixDriver. These examples are extracted from open source projects. 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 Project: phoenix   Source File: MetaDataRegionObserver.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void postOpen(ObserverContext<RegionCoprocessorEnvironment> e) {
    if (!enableRebuildIndex) {
        LOG.info("Failure Index Rebuild is skipped by configuration.");
        return;
    }
    // turn off verbose deprecation logging
    Logger deprecationLogger = Logger.getLogger("org.apache.hadoop.conf.Configuration.deprecation");
    if (deprecationLogger != null) {
        deprecationLogger.setLevel(Level.WARN);
    }
    try {
        Class.forName(PhoenixDriver.class.getName());
        // starts index rebuild schedule work
        BuildIndexScheduleTask task = new BuildIndexScheduleTask(e.getEnvironment());
        // run scheduled task every 10 secs
        executor.scheduleAtFixedRate(task, 10000, rebuildIndexTimeInterval, TimeUnit.MILLISECONDS);
    } catch (ClassNotFoundException ex) {
        LOG.error("BuildIndexScheduleTask cannot start!", ex);
    }
}
 
Example 2
Source Project: phoenix   Source File: CsvBulkLoadToolIT.java    License: Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void tearDownAfterClass() throws Exception {
    try {
        conn.close();
    } finally {
        try {
            PhoenixDriver.INSTANCE.close();
        } finally {
            try {
                DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);
            } finally {                    
                try {
                    hbaseTestUtil.shutdownMiniMapReduceCluster();
                } finally {
                    hbaseTestUtil.shutdownMiniCluster();
                }
            }
        }
    }
}
 
Example 3
Source Project: phoenix   Source File: PhoenixMetricsDisabledIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static synchronized void doSetup() throws Exception {
    final Configuration conf = HBaseConfiguration.create();
    conf.set(QueryServices.GLOBAL_METRICS_ENABLED, String.valueOf(false));
    conf.set(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false));
    // Clear the cached singletons so we can inject our own.
    InstanceResolver.clearSingletons();
    // Make sure the ConnectionInfo doesn't try to pull a default Configuration
    InstanceResolver.getSingleton(ConfigurationFactory.class, new ConfigurationFactory() {
        @Override
        public Configuration getConfiguration() {
            return conf;
        }
        @Override
        public Configuration getConfiguration(Configuration confToClone) {
            Configuration copy = new Configuration(conf);
            copy.addResource(confToClone);
            return copy;
        }
    });

    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));

    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}
 
Example 4
@BeforeClass
public static synchronized void setUp() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    hbaseTestUtil = new HBaseTestingUtility(conf);
    setUpConfigForMiniCluster(conf);

    //Enforce the limit of the result, so scans will stop between cells.
    conf.setLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, 5);
    conf.setLong(HConstants.HBASE_SERVER_SCANNER_MAX_RESULT_SIZE_KEY, 5);

    hbaseTestUtil.startMiniCluster();
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;

    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}
 
Example 5
Source Project: phoenix   Source File: RebuildIndexConnectionPropsIT.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static synchronized void doSetup() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    hbaseTestUtil = new HBaseTestingUtility(conf);
    Map<String, String> serverProps = new HashMap<>();
    serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    // need at least one retry otherwise test fails
    serverProps.put(QueryServices.INDEX_REBUILD_RPC_RETRIES_COUNTER, Long.toString(NUM_RPC_RETRIES));
    setUpConfigForMiniCluster(conf, new ReadOnlyProps(serverProps.entrySet().iterator()));
    hbaseTestUtil.startMiniCluster();
    // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
    Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
    try (PhoenixConnection phxConn =
            DriverManager.getConnection(url, driverProps).unwrap(PhoenixConnection.class)) {
    }
}
 
Example 6
Source Project: presto   Source File: PhoenixClientModule.java    License: Apache License 2.0 5 votes vote down vote up
private void checkConfiguration(String connectionUrl)
{
    try {
        PhoenixDriver driver = PhoenixDriver.INSTANCE;
        checkArgument(driver.acceptsURL(connectionUrl), "Invalid JDBC URL for Phoenix connector");
    }
    catch (SQLException e) {
        throw new PrestoException(PHOENIX_CONFIG_ERROR, e);
    }
}
 
Example 7
Source Project: phoenix   Source File: CsvToKeyValueMapper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void setup(Context context) throws IOException, InterruptedException {

    Configuration conf = context.getConfiguration();
    String jdbcUrl = getJdbcUrl(conf);

    // pass client configuration into driver
    Properties clientInfos = new Properties();
    Iterator<Entry<String, String>> iterator = conf.iterator();
    while(iterator.hasNext()) {
        Entry<String,String> entry = iterator.next();
        clientInfos.setProperty(entry.getKey(), entry.getValue());
    }
    
    // This statement also ensures that the driver class is loaded
    LOG.info("Connection with driver {} with url {}", PhoenixDriver.class.getName(), jdbcUrl);

    try {
        conn = (PhoenixConnection) DriverManager.getConnection(jdbcUrl, clientInfos);
    } catch (SQLException e) {
        throw new RuntimeException(e);
    }

    upsertListener = new MapperUpsertListener(
            context, conf.getBoolean(IGNORE_INVALID_ROW_CONFKEY, true));
    csvUpsertExecutor = buildUpsertExecutor(conf);
    csvLineParser = new CsvLineParser(conf.get(FIELD_DELIMITER_CONFKEY).charAt(0), conf.get(QUOTE_CHAR_CONFKEY).charAt(0),
            conf.get(ESCAPE_CHAR_CONFKEY).charAt(0));

    preUpdateProcessor = loadPreUpsertProcessor(conf);
    if(!conf.get(CsvToKeyValueMapper.INDEX_TABLE_NAME_CONFKEY, "").isEmpty()){
    	tableName = Bytes.toBytes(conf.get(CsvToKeyValueMapper.INDEX_TABLE_NAME_CONFKEY));
    } else {
    	tableName = Bytes.toBytes(conf.get(CsvToKeyValueMapper.TABLE_NAME_CONFKEY, ""));
    }
}
 
Example 8
Source Project: phoenix   Source File: QueryUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static String getConnectionUrl(Properties props, Configuration conf)
        throws ClassNotFoundException, SQLException {
    // make sure we load the phoenix driver
    Class.forName(PhoenixDriver.class.getName());

    // read the hbase properties from the configuration
    String server = ZKConfig.getZKQuorumServersString(conf);
    // could be a comma-separated list
    String[] rawServers = server.split(",");
    List<String> servers = new ArrayList<String>(rawServers.length);
    boolean first = true;
    int port = -1;
    for (String serverPort : rawServers) {
        try {
            server = Addressing.parseHostname(serverPort);
            int specifiedPort = Addressing.parsePort(serverPort);
            // there was a previously specified port and it doesn't match this server
            if (port > 0 && specifiedPort != port) {
                throw new IllegalStateException("Phoenix/HBase only supports connecting to a " +
                        "single zookeeper client port. Specify servers only as host names in " +
                        "HBase configuration");
            }
            // set the port to the specified port
            port = specifiedPort;
            servers.add(server);
        } catch (IllegalArgumentException e) {
        }
    }
    // port wasn't set, shouldn't ever happen from HBase, but just in case
    if (port == -1) {
        port = conf.getInt(QueryServices.ZOOKEEPER_PORT_ATTRIB, -1);
        if (port == -1) {
            throw new RuntimeException("Client zk port was not set!");
        }
    }
    server = Joiner.on(',').join(servers);

    return getUrl(server, port);
}
 
Example 9
Source Project: phoenix   Source File: CsvBulkLoadToolIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    hbaseTestUtil = new HBaseTestingUtility();
    Configuration conf = hbaseTestUtil.getConfiguration();
    setUpConfigForMiniCluster(conf);
    hbaseTestUtil.startMiniCluster();
    hbaseTestUtil.startMiniMapReduceCluster();

    Class.forName(PhoenixDriver.class.getName());
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    conn = DriverManager.getConnection(PhoenixRuntime.JDBC_PROTOCOL
            + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum);
}
 
Example 10
Source Project: phoenix   Source File: PhoenixHBaseLoaderIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
    hbaseTestUtil = new HBaseTestingUtility();
    conf = hbaseTestUtil.getConfiguration();
    setUpConfigForMiniCluster(conf);
    conf.set(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
    hbaseTestUtil.startMiniCluster();

    Class.forName(PhoenixDriver.class.getName());
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    props.put(QueryServices.DROP_METADATA_ATTRIB, Boolean.toString(true));
    conn = DriverManager.getConnection(PhoenixRuntime.JDBC_PROTOCOL +
             PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum,props);
 }
 
Example 11
Source Project: phoenix   Source File: BasePhoenixMetricsIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(3);
    // Disable system task handling
    props.put(QueryServices.TASK_HANDLING_INITIAL_DELAY_MS_ATTRIB, Long.toString(Long.MAX_VALUE));
    // Phoenix Global client metrics are enabled by default
    // Enable request metric collection at the driver level
    props.put(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, String.valueOf(true));
    // disable renewing leases as this will force spooling to happen.
    props.put(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false));
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
    // need the non-test driver for some tests that check number of hconnections, etc.
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);

}
 
Example 12
@AfterClass
public static synchronized void tearDownAfterClass() throws Exception {
    try {
        DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);
    } finally {
        hbaseTestUtil.shutdownMiniCluster();
    }
}
 
Example 13
@BeforeClass
public static synchronized void doSetup() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    HBaseTestingUtility hbaseTestUtil = new HBaseTestingUtility(conf);
    setUpConfigForMiniCluster(conf);
    conf.set(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    conf.set(QueryServices.DROP_METADATA_ATTRIB, Boolean.TRUE.toString());
    conf.set(QueryServices.MUTATE_BATCH_SIZE_ATTRIB, Integer.toString(3000));
    hbaseTestUtil.startMiniCluster();
    // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
    String zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}
 
Example 14
Source Project: phoenix   Source File: ConnectionUtilIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void setUp() throws Exception {
    hbaseTestUtil = new HBaseTestingUtility();
    conf = hbaseTestUtil.getConfiguration();
    setUpConfigForMiniCluster(conf);
    conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/hbase-test");
    hbaseTestUtil.startMiniCluster();
    Class.forName(PhoenixDriver.class.getName());
}
 
Example 15
Source Project: phoenix   Source File: PhoenixDriverIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void setUp() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    hbaseTestUtil = new HBaseTestingUtility(conf);
    setUpConfigForMiniCluster(conf);
    conf.set(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    hbaseTestUtil.startMiniCluster();
    // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}
 
Example 16
Source Project: phoenix   Source File: QueryLoggerIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void doSetup() throws Exception {
    Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
    // Enable request metric collection at the driver level
    props.put(QueryServices.COLLECT_REQUEST_LEVEL_METRICS, String.valueOf(true));
    // disable renewing leases as this will force spooling to happen.
    props.put(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false));
    setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
    // need the non-test driver for some tests that check number of hconnections, etc.
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}
 
Example 17
Source Project: phoenix   Source File: BackwardCompatibilityIT.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public synchronized void doSetup() throws Exception {
    conf = HBaseConfiguration.create();
    hbaseTestUtil = new HBaseTestingUtility(conf);
    setUpConfigForMiniCluster(conf);
    conf.set(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
    hbaseTestUtil.startMiniCluster();
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
}
 
Example 18
Source Project: phoenix   Source File: BackwardCompatibilityIT.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void cleanUpAfterTest() throws Exception {
    try {
        DriverManager.deregisterDriver(PhoenixDriver.INSTANCE);
    } finally {
        hbaseTestUtil.shutdownMiniCluster();
    }
}
 
Example 19
Source Project: phoenix   Source File: ScannerLeaseRenewalIT.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static synchronized void setUp() throws Exception {
    Configuration conf = HBaseConfiguration.create();
    hbaseTestUtil = new HBaseTestingUtility(conf);
    setUpConfigForMiniCluster(conf);
    conf.setLong(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, LEASE_TIMEOUT_PERIOD_MILLIS);
    hbaseTestUtil.startMiniCluster();
    // establish url and quorum. Need to use PhoenixDriver and not PhoenixTestDriver
    zkQuorum = "localhost:" + hbaseTestUtil.getZkCluster().getClientPort();
    url = PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + zkQuorum;

    Properties driverProps = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    driverProps.put(RENEW_LEASE_THREAD_POOL_SIZE, Long.toString(4));
    
    // if this property is false, tests will fail with UnknownScannerException errors. 
    driverProps.put(RENEW_LEASE_ENABLED, Boolean.toString(true));
    
    driverProps.put(RENEW_LEASE_THRESHOLD_MILLISECONDS,
        Long.toString(LEASE_TIMEOUT_PERIOD_MILLIS / 2));
    driverProps.put(RUN_RENEW_LEASE_FREQUENCY_INTERVAL_MILLISECONDS,
        Long.toString(LEASE_TIMEOUT_PERIOD_MILLIS / 4));
    driverProps.put(HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD,
        Long.toString(LEASE_TIMEOUT_PERIOD_MILLIS));
    // use round robin iterator
    driverProps.put(FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.toString(false));
    DriverManager.registerDriver(PhoenixDriver.INSTANCE);
    try (PhoenixConnection phxConn = DriverManager.getConnection(url, driverProps).unwrap(PhoenixConnection.class)) {
        // run test methods only if we are at the hbase version that supports lease renewal.
        Assume.assumeTrue(phxConn.getQueryServices().supportsFeature(Feature.RENEW_LEASE));
    }
}
 
Example 20
Source Project: phoenix   Source File: ConnectionlessTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void verifyDriverRegistered() throws SQLException {
    assertTrue(DriverManager.getDriver(getUrl()) == PhoenixDriver.INSTANCE);
}
 
Example 21
Source Project: phoenix   Source File: ConnectionlessTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static synchronized void verifyDriverRegistered() throws SQLException {
    assertTrue(DriverManager.getDriver(getUrl()) == PhoenixDriver.INSTANCE);
}