- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我尝试创建一个简单的类来创建表并使用 HBase 和 Google 应用引擎添加一些列。我已经在 Google Cloud 平台中创建了一个项目和一个实例。我克隆了这个存储库:https://github.com/GoogleCloudPlatform/cloud-bigtable-examples/blob/master/java/hello-world/src/main/java/com/example/cloud/bigtable/helloworld/HelloWorld.java在我的实例中创建一个表就像一个魅力。但是当我尝试使用相同的配置创建一个新的 Maven 项目时,它不起作用,我无法创建任何内容。我遇到了这个问题:
InvocationTargetException: Could not find an appropriate constructor for com.google.cloud.bigtable.hbase1_x.BigtableConnection: com.google.common.util.concurrent.MoreExecutors.platformThreadFactory()Ljava/util/concurrent/ThreadFactory;
这是我的 AudioBridgeData.java 文件:
package com.xxx.xxx;
import com.google.cloud.bigtable.hbase.BigtableConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
/**
* A minimal application that connects to Cloud Bigtable using the native HBase API
* and performs some basic operations.
*/
public class AudioBridgeData {
private static final byte[] TABLE_NAME = Bytes.toBytes("audio-bridge");
private static final byte[] COLUMN_FAMILY_NAME = Bytes.toBytes("phone-number");
private static final byte[] COLUMN_NAME = Bytes.toBytes("number");
private static final String[] NUMBERS =
{ "+33697584976", "+19553560976", "+4879665676" };
/**
* Connects to Cloud Bigtable, runs some basic operations and prints the results.
*/
private static void doAudioBridge(String projectId, String instanceId) {
try (Connection connection = BigtableConfiguration.connect(projectId, instanceId)) {
Admin admin = connection.getAdmin();
HTableDescriptor descriptor = new HTableDescriptor(TableName.valueOf(TABLE_NAME));
descriptor.addFamily(new HColumnDescriptor(COLUMN_FAMILY_NAME));
print("Create table " + descriptor.getNameAsString());
admin.createTable(descriptor);
Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
print("Write some numbers to the table");
for (int i = 0; i < NUMBERS.length; i++) {
Put put = new Put(Bytes.toBytes(i));
put.addColumn(COLUMN_FAMILY_NAME, COLUMN_NAME, Bytes.toBytes(NUMBERS[i]));
table.put(put);
}
int rowKey = 0;
Result getResult = table.get(new Get(Bytes.toBytes(rowKey)));
String number = Bytes.toString(getResult.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME));
System.out.println("Get a single number by row key");
System.out.printf("\t%s = %s\n", rowKey, number);
Scan scan = new Scan();
print("Scan for all numbers:");
ResultScanner scanner = table.getScanner(scan);
for (Result row : scanner) {
byte[] valueBytes = row.getValue(COLUMN_FAMILY_NAME, COLUMN_NAME);
System.out.println('\t' + Bytes.toString(valueBytes));
}
} catch (IOException e) {
System.err.println("Exception while running HelloWorld: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
private static void print(String msg) {
System.out.println("Number: " + msg);
}
public static void main(String[] args) {
String projectId = requiredProperty("bigtable.projectID");
String instanceId = requiredProperty("bigtable.instanceID");
doAudioBridge(projectId, instanceId);
}
private static String requiredProperty(String prop) {
String value = System.getProperty(prop);
if (value == null) {
throw new IllegalArgumentException("Missing required system property: " + prop);
}
return value;
}
}
这是我的 pom.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<url>http://maven.apache.org</url>
<name>xxx</name>
<properties>
<bigtable.version>1.0.0-pre1</bigtable.version>
<hbase.version>1.1.5</hbase.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-1.x</artifactId>
<version>${bigtable.version}</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>1.1.33.Fork26</version>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>0.98.11-hadoop2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<mainClass>com.xxx.xxx.AudioBridgeData</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
我尝试运行这个命令:
mvn exec:java -Dbigtable.projectID=xxx -Dbigtable.instanceID=quickstart-instance
非常感谢您的帮助! :)
最佳答案
我有同样的错误消息,奇怪的是它是由于缺少应用程序凭据引起的。如果是同样的问题,您应该设置此环境变量:
GOOGLE_APPLICATION_CREDENTIALS
应将其设置为您(可能已)在创建服务帐户 key 后下载的客户端凭据文件的位置。这是一个很好的页面:
https://developers.google.com/identity/protocols/application-default-credentials
关于java - 找不到 com.google.cloud.bigtable.hbase1_x.BigtableConnection 的合适构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45513367/
我必须数据框,df1 有列 A、B、C、D... 和 df2 有列 A , B, E, F... 我要合并的键在 A 列中。 B 在两个数据框中也(很可能)相同。虽然这是一个大数据集,但我正在清理,所
我有 2 个不同的类,但原始类型声明相同,如下所示 int x = 0; - (void)viewDidLoad{ [super viewDidLoad]; } 如果我将其中一个名称“x”更改为“y”
我需要对一个 c 文件/模块进行单元测试,该文件包含: /* Import the _x symbol from assem.S */ extern void _x; 该变量稍后在该文件中用作: #d
我有剧作家测试,我用这个命令运行测试:npx folio。 但是当我运行测试时,我收到了这个错误信息: 第一个参数必须使用对象解构模式:_x 我确实尝试删除 .babelrc 文件,它应该根据这个 t
下面的代码总是返回下面的有线对象 {"_U": 0, "_V": 0, "_W": null, "_X": null} 作为回应。 这是我的代码 getData = () => {
我是一名优秀的程序员,十分优秀!