Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2444 HostDB CSV dumper to emit field header by default

Markus Jelsmad7e4046e6e72
diff --git a/src/java/org/apache/nutch/hostdb/ReadHostDb.java b/src/java/org/apache/nutch/hostdb/ReadHostDb.java
index 54649e46e..28a7eb709 100644
--- a/src/java/org/apache/nutch/hostdb/ReadHostDb.java
+++ b/src/java/org/apache/nutch/hostdb/ReadHostDb.java
@@ -62,6 +62,7 @@ public class ReadHostDb extends Configured implements Tool {
private static final Logger LOG = LoggerFactory
.getLogger(MethodHandles.lookup().lookupClass());
+ public static final String HOSTDB_DUMP_HEADER = "hostdb.dump.field.header";
public static final String HOSTDB_DUMP_HOSTNAMES = "hostdb.dump.hostnames";
public static final String HOSTDB_DUMP_HOMEPAGES = "hostdb.dump.homepages";
public static final String HOSTDB_FILTER_EXPRESSION = "hostdb.filter.expression";
@@ -69,12 +70,14 @@ public class ReadHostDb extends Configured implements Tool {
static class ReadHostDbMapper extends Mapper<Text, HostDatum, Text, Text> {
protected boolean dumpHostnames = false;
protected boolean dumpHomepages = false;
+ protected boolean fieldHeader = true;
protected Text emptyText = new Text();
protected Expression expr = null;
public void setup(Context context) {
dumpHomepages = context.getConfiguration().getBoolean(HOSTDB_DUMP_HOMEPAGES, false);
dumpHostnames = context.getConfiguration().getBoolean(HOSTDB_DUMP_HOSTNAMES, false);
+ fieldHeader = context.getConfiguration().getBoolean(HOSTDB_DUMP_HEADER, true);
String expr = context.getConfiguration().get(HOSTDB_FILTER_EXPRESSION);
if (expr != null) {
// Create or retrieve a JexlEngine
@@ -89,7 +92,12 @@ public class ReadHostDb extends Configured implements Tool {
}
}
- public void map(Text key, HostDatum datum, Context context) throws IOException, InterruptedException {
+ public void map(Text key, HostDatum datum, Context context) throws IOException, InterruptedException {
+ if (fieldHeader && !dumpHomepages && !dumpHostnames) {
+ context.write(new Text("hostname"), new Text("unfetched\tfetched\tgone\tredirTemp\tredirPerm\tredirSum\tok\tnumRecords\tdnsFail\tcnxFail\tsumFail\tscore\tlastCheck\thomepage\tmetadata"));
+ fieldHeader = false;
+ }
+
if (expr != null) {
// Create a context and add data
JexlContext jcontext = new MapContext();