3. 添加phoenix-core-4.0.0-incubating.jar到所有HBase region server的classpath(copy it into the HBase lib directory)中
Add the phoenix-core-[version]-incubating.jar to the classpath of every HBase region server. An easy way to do this is to copy it into the HBase lib directory.
5. Add the phoenix-[version]-incubating-client.jar to the classpath of any Phoenix client (both Hadoop-1 or Hadoop-2 compatible client jars are available in latest release).
scott@master:/opt/phoenix-4.0.0$ sqlline.py master:2181
Setting property: [isolation, TRANSACTION_READ_COMMITTED]issuing: !connect jdbc:phoenix:master:2181 none none org.apache.phoenix.jdbc.PhoenixDriver
Connecting to jdbc:phoenix:master:2181
Connected to: Phoenix (version 4.0)Driver: org.apache.phoenix.jdbc.PhoenixDriver (version 4.0)Autocommit status: trueTransaction isolation: TRANSACTION_READ_COMMITTED
Building list of tables and columns for tab-completion (set fastconnect to true to skip)...
53/53 (100%) Done
Done
sqlline version 1.1.2
0: jdbc:phoenix:master:2181>
scott@master:/opt/phoenix-4.0.0$sqlline.pymaster:2181./examples/STOCK_SYMBOL.sqlSettingproperty:[isolation,TRANSACTION_READ_COMMITTED]Settingproperty:[run,./examples/STOCK_SYMBOL.sql]issuing:!connectjdbc:phoenix:master:2181nonenoneorg.apache.phoenix.jdbc.PhoenixDriverConnectingtojdbc:phoenix:master:2181Connectedto:Phoenix(version4.0)Driver:org.apache.phoenix.jdbc.PhoenixDriver(version4.0)Autocommitstatus:trueTransactionisolation:TRANSACTION_READ_COMMITTEDBuildinglistoftablesandcolumnsfortab-completion(setfastconnecttotruetoskip)...55/55(100%)DoneDone1/52/5/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */-- creates stock table with single row CREATETABLEIFNOTEXISTSSTOCK_SYMBOL(SYMBOLVARCHARNOTNULLPRIMARYKEY,COMPANYVARCHAR);Norowsaffected(0.751seconds)3/5UPSERTINTOSTOCK_SYMBOLVALUES('CRM','SalesForce.com');1rowaffected(0.099seconds)4/5SELECT*FROMSTOCK_SYMBOL;+------------+------------+|SYMBOL|COMPANY|+------------+------------+|CRM|SalesForce.com|+------------+------------+1rowselected(0.078seconds)5/5Closing:org.apache.phoenix.jdbc.PhoenixConnectionsqllineversion1.1.2
scott@master:/opt/phoenix-4.0.0/examples$ psql.py -t EXAMPLE master:2181 data.csv
csv columns from database.
CSV Upsert complete. 2 rows upserted
Time: 0.072 sec(s)
psql参数明细
The following parameters can be used for loading data with PSQL:
123456
Parameter Description
-t Provide the name of the table in which to load data. By default, the name of the table is taken from the name of the CSV file.
-h Overrides the column names to which the CSV data maps and is case sensitive. A special value of in-line indicating that the first line of the CSV file determines the column to which the data maps.
-s Run in strict mode, throwing an error on CSV parsing errors
-d Supply a custom delimiter or delimiters for CSV parsing
-a Supply an array delimiter (explained in more detail below)
7.2 Loading via MapReduce
1
hadoop jar /opt/phoenix-4.0.0/hadoop-2/phoenix-4.0.0-incubating-client.jar org.apache.phoenix.mapreduce.CsvBulkLoadTool --table EXAMPLE --input /input/example.csv
遇到的问题
hbase-default.xml file seems to be for and old version of HBase (0.98.1-hadoop1), this version is 0.98.1-hadoop2
1234567891011121314
hadoop jar /opt/phoenix-4.0.0/hadoop-2/phoenix-4.0.0-incubating-client.jar org.apache.phoenix.mapreduce.CsvBulkLoadTool --table EXAMPLE --input /input/example.csv
Exception in thread "main" java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (0.98.1-hadoop1), this version is 0.98.1-hadoop2
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:70) at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:102) at org.apache.phoenix.mapreduce.CsvBulkLoadTool.run(CsvBulkLoadTool.java:159) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:84) at org.apache.phoenix.mapreduce.CsvBulkLoadTool.main(CsvBulkLoadTool.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
<propertyskipInDoc="true"><name>hbase.defaults.for.version</name><value>0.98.1-hadoop1</value><description>This defaults file was compiled for version ${project.version}. This variable is used
to make sure that a user doesn't have an old version of hbase-default.xml on the
classpath.</description></property>
修改为
1234567
<propertyskipInDoc="true"><name>hbase.defaults.for.version</name><value>0.98.1-hadoop2</value><description>This defaults file was compiled for version ${project.version}. This variable is used
to make sure that a user doesn't have an old version of hbase-default.xml on the
classpath.</description></property>
<property><name>hbase.defaults.for.version.skip</name><value>true</value><description>Set to true to skip the 'hbase.defaults.for.version' check.
Setting this to true can be useful in contexts other than
the other side of a maven generation; i.e. running in an
ide. You'll want to set this boolean to true to avoid
seeing the RuntimException complaint: "hbase-default.xml file
seems to be for and old version of HBase (\${hbase.version}), this
version is X.X.X-SNAPSHOT"</description></property>
Remove prior phoenix-[version]-client.jar from the lib directory of SQuirrel
Copy the phoenix-[version]-client.jar into the lib directory of SQuirrel (Note that on a Mac, this is the internal lib directory).
Start SQuirrel and add new driver to SQuirrel (Drivers –> New Driver)
In Add Driver dialog box, set Name to Phoenix
Press List Drivers button and org.apache.phoenix.jdbc.PhoenixDriver should be automatically populated in the Class Name textbox. Press OK to close this dialog.
Switch to Alias tab and create the new Alias (Aliases –> New Aliases)
In the dialog box, Name: any name, Driver: Phoenix, User Name: anything, Password: anything
Construct URL as follows: jdbc:phoenix: zookeeper quorum server. For example, to connect to a local HBase use: jdbc:phoenix:localhost
Press Test (which should succeed if everything is setup correctly) and press OK to close.
Now double click on your newly created Phoenix alias and click Connect. Now you are ready to run SQL queries against Phoenix.