我正按照Cassandra blog中提供的简单示例尝试使用CQLSSTableWriter
。
我的项目依赖项是:
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'com.datastax.cassandra:cassandra-driver-core:2.1.9'
compile 'org.apache.cassandra:cassandra-all:2.2.4'
testCompile group: 'junit', name: 'junit', version: '4.11'
这是我的代码:
Application.groovy
package com.example
import org.apache.cassandra.io.sstable.CQLSSTableWriter
class Application {
public static void main(String[] args) {
def schema = """create table example.new_table (
name ascii,
value ascii
PRIMARY KEY (name));"""
def insert = """INSERT INTO example.new_table
(name, value)
VALUES ( ?, ? )"""
def outputDir = "/Users/me/datadump"
def writer = CQLSSTableWriter.builder()
.inDirectory(outputDir)
.forTable(schema)
.using(insert)
.build()
writer.close()
}
}
此代码导致以下异常:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.cassandra.cql3.QueryProcessor.getStatement(QueryProcessor.java:491)
at org.apache.cassandra.io.sstable.CQLSSTableWriter$Builder.getStatement(CQLSSTableWriter.java:514)
at org.apache.cassandra.io.sstable.CQLSSTableWriter$Builder.forTable(CQLSSTableWriter.java:361)
at org.apache.cassandra.io.sstable.CQLSSTableWriter$Builder$forTable$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.example.Application.main(Application.groovy:24)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.RuntimeException: java.net.UnknownHostException: COMP: COMP: nodename nor servname provided, or not known
at org.apache.cassandra.utils.FBUtilities.getLocalAddress(FBUtilities.java:136)
at org.apache.cassandra.tracing.Tracing.<init>(Tracing.java:81)
at org.apache.cassandra.tracing.Tracing.<clinit>(Tracing.java:87)
... 13 more
Caused by: java.net.UnknownHostException: COMP: COMP: nodename nor servname provided, or not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1475)
at org.apache.cassandra.utils.FBUtilities.getLocalAddress(FBUtilities.java:131)
... 15 more
Caused by: java.net.UnknownHostException: COMP: nodename nor servname provided, or not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)
at java.net.InetAddress.getLocalHost(InetAddress.java:1471)
... 16 more
Process finished with exit code 1
使用CQLSSTableWriter
的所有示例看起来都非常像我的代码。我的依赖项是否存在版本冲突?我想也许是因为异常告诉我它甚至无法加载Tracing
类。
答案 0 :(得分:0)
按照https://stackoverflow.com/a/1881967/953327中的建议解决了当前问题。
我需要在/etc/hosts
文件中添加一个条目。