I have two input files smt.txt and smo.txt. The jar file reads the text files and split the data according to some rule which is described in java file. And the pig file takes these data put into output files with doing mapreduce.
register 'maprfs:///user/username/fl.jar';
DEFINE FixedLoader fl();
mt = load 'maprfs:///user/username/smt.txt' using FixedLoader('-30','30-33',...........) AS (.........);
mo = load 'maprfs:///user/username/smo.txt*' using FixedLoader('-30','30-33',.....) AS (......);
store mt into 'maprfs:///user/username/mt_out' using JsonStorage();
store mo into 'maprfs:///user/username/mo_out' using JsonStorage();
and a part of java code like in the following. (The content of methods are not neccessary I believe):
package com.mapr.util;
import org.apache.hadoop.mapreduce.lib.input.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.io.*;
import org.apache.pig.*;
import org.apache.pig.data.*;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.*;
import java.util.*;
import java.io.*;
public class FixedLoader extends LoadFunc
{
............
}
When I run this pig program in a teminal with the command "pig -x mapreduce sample.pig", I gave an Error message:
ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1070: Could not resolve com.mapr.util.FixedLoader using imports: [, org.apache.pig.builtin., org.apache.pig.impl.builtin.]
How can I import these into my project or are there any suggestions/solutions to run this program?
You need to define FixedLoader with its full package name:
register 'maprfs:///user/username/fl.jar';
DEFINE FixedLoader com.mapr.util.FixedLoader();
...
Also register all of the 3rd party dependency jars that are used in your custom UDF.
Related
I have been trying to compile my Java code using the format javac Main.java but for some reason the compiler says that my package does not exist and as a matter of fact it is in the project structure, here is a screenshot:
The exact error is: Main.java:1: error: package com.fasterxml.jackson.databind does not exist import com.fasterxml.jackson.databind.ObjectMapper;
And my code looks like this in my Main.java:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
public final class Main {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Usage: Main [file path]");
return;
}
UdacisearchClient client =
new UdacisearchClient(
"CatFacts LLC",
17,
8000,
5,
Instant.now(),
Duration.ofDays(180),
ZoneId.of("America/Los_Angeles"),
"555 Meowmers Ln, Riverside, CA 92501");
Path outputPath = Path.of(args[0]);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.writeValue(Files.newBufferedWriter(outputPath), client);
System.out.println("Wrote to: "+ outputPath.toAbsolutePath());
UdacisearchClient deserialized = objectMapper.
readValue(Files.newBufferedReader(outputPath), UdacisearchClient.class);
System.out.println("Deserialized: " + deserialized);
}
}
The whole code is supposed to compile like this javac Main.java and then java Main client.json. When I try to compile it by going to Run, Edit Configurations and by adding client.json as the argument of my program it works like a charm, my object is serialized as a json object in the client.json file but when I compile using command line it says no package is found. The same error happens for any other dependency I try to use. It should be noted that when I instantiate objects from my dependency it looks fine as the import lines related to those objects aren't red. So I guess my issue resides in my command line compilation or my Intellij environment. I have tried many of the solution proposed online but the problem remains. I would like some help please.
It turns out the solution was simple.
First compiling the libraries inside the lib folder and Main.java doing :
javac -cp ".;lib/*" Main.java
Then running my class Main (containing my main function):
java -cp ".;lib/*" Main
I was missing on the dot "." and the semicolon ;!
I am attempting to copy and rename a file on my local machine (Win 7) using Bean Shell Sampler in JMeter 3.0 (Java v1.8). The idea is to create the new file with a unique name and have the name saved as a variable that can be used in place of the file name in an FTP PUT request.
Here is the code I am using for the copy and rename:
import java.text.*;
import java.nio.file.StandardCopyOption.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
String filename = new SimpleDateFormat("dd-MM-yyyy_hh:mm:ss").format(new Date())+".xlsx";
log.info(filename);
Path source = Paths.get("C:/dropfile/qatp/QATP_GuestRecords.xlsx");
Path target = Paths.get("C:/dropfile/qatp/"+filename);
Files.copy(source, target, REPLACE_EXISTING);
The error I am receiving in the log:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method:
eval Sourced file: inline evaluation of: ``import java.text.; import
java.nio.file.StandardCopyOption.; import java.io.IO . . . '' : Typed
variable declaration : Error in method invocation: Static method get(
java.lang.String ) not found in class'java.nio.file.Paths'
I have been searching for an answer to this issue and came across a solution where the suggestion was:
"My guess is that the problem is that it's not populating the varargs parameter. Try:
Path target = Paths.get(filename, new String[0]);"
I tried this solution by modifying my code like so:
import java.text.*;
import java.nio.file.StandardCopyOption.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
String filename = new SimpleDateFormat("dd-MM-yyyy_hh:mm:ss").format(new Date())+".xlsx";
log.info(filename);
Path source = Paths.get("C:/dropfile/qatp/QATP_GuestRecords.xlsx", new String[0]);
Path target = Paths.get("C:/dropfile/qatp/"+filename, new String[0]);
Files.copy(source, target, REPLACE_EXISTING);
And received this error:
ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method:
eval Sourced file: inline evaluation of: ``import java.text.; import
java.nio.file.StandardCopyOption.; import java.io.IO . . . '' : Typed
variable declaration : Method Invocation Paths.get
Does anyone know why I am hitting this error and how to get around it?
Even in plain old Java this is a misleading use of Paths.get, which takes an URI, or an array of strings (varargs). See javadoc.
In Java what you tried works because the static typing allow the compiler to determine that you are passing an array of a single String. Apparently BeanShell does not and gets confused. The trick suggested in the other answer is not a good one in my opinion: again in Java it would work, by joining the two strings (2nd one is empty, so result is 1st string, which is what you want), but it confuses BeanShell all the same because there is another static get method that takes 2 arguments.
If you already have the path as a single String, try this instead:
Path source = new File("C:/dropfile/qatp/QATP_GuestRecords.xlsx").toPath();
Alternatively, you could use Paths.get like this:
Path source = Paths.get("C:", "dropfile", "qatp", "QATP_GuestRecords.xlsx");
Or like this (varargs is syntaxic sugar to help pass an array):
Path source = Paths.get(new String [] { "C:/dropfile/qatp/QATP_GuestRecords.xlsx" });
It's perfectly valid to pass fragments of path as arguments, or the entire path string as single argument, but that seems to trip BeanShell, so, better avoid Paths.get in BeanShell, unless you pass an array explicitly as in last example.
Beanshell != Java, it doesn't support all the Java features (think about it as about Java 1.5 and amend your code appropriately.
So I would recommend switching to JSR223 Sampler and Groovy language, Groovy is much more Java-compliant and performs much better.
Also be aware that you can use FileUtils.copyFile() method which will work for both Beanshell and/or Groovy
import org.apache.commons.io.FileUtils;
import java.text.SimpleDateFormat;
String filename = new SimpleDateFormat("dd-MM-yyyy_hh:mm:ss").format(new Date()) + ".xlsx";
FileUtils.copyFile(new File("/tmp/QATP_GuestRecords.xlsx"), new File("/tmp/" + filename));
See Groovy is the New Black article for more information on using Groovy language in JMeter test scripts.
I am trying to use the hadoop map reduce, but instead of mapping each line at a time in my Mapper, I would like to map a whole file at once.
So I have found these two classes
(https://code.google.com/p/hadoop-course/source/browse/HadoopSamples/src/main/java/mr/wholeFile/?r=3)
That suppose to help me do this.
And I got a compilation error that says :
The method setInputFormat(Class) in the type
JobConf is not applicable for the arguments
(Class) Driver.java /ex2/src line 33 Java
Problem
I changed my Driver class to be
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.InputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import forma.WholeFileInputFormat;
/*
* Driver
* The Driver class is responsible of creating the job and commiting it.
*/
public class Driver {
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(Driver.class);
conf.setJobName("Get minimun for each month");
conf.setOutputKeyClass(IntWritable.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
// previous it was
// conf.setInputFormat(TextInputFormat.class);
// And it was changed it to :
conf.setInputFormat(WholeFileInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf,new Path("input"));
FileOutputFormat.setOutputPath(conf,new Path("output"));
System.out.println("Starting Job...");
JobClient.runJob(conf);
System.out.println("Job Done!");
}
}
What am I doing wrong?
Make sure your wholeFileInputFormat class has correct imports. You are using old MapReduce Api in your job Driver. I think you imported new API FileInputFormat in your WholeFileInputFormat class. If i am right, You should import org.apache.hadoop.mapred.FileInputFormat in your wholeFileInputFormat class instead of org.apache.hadoop.mapreduce.lib.input.FileInputFormat .
Hope this helps.
Easiest way to do this is to gzip your input file. This will make FileInputFormat.isSplitable() to return false.
We too ran into something similar and had an alternative out-of-box approach.
Let say you need to process 100 large files (f1, f2,...,f100) such that you need to read one file wholly in the map function. So instead of using the "WholeInputFileFormat" reader approach we created equivalent 10 text files (p1, p2,...,p10) each file containing either the HDFS URL or web URL of the f1-f100 files.
Thus p1 will contain url for f1-f10, p2 will urls for f11-f20 and so on.
These new files p1 thru p10 are then used as input to mappers. Thus the mapper m1 processing file p1 will open file f1 thru f10 one at a time and process it wholly.
This approach allowed us to control the number of mappers and write more exhaustive and complex application logic in map-reduce application. E.g we could run NLP on PDF files using this approach.
Sorry for this noobie question, I'm new to Java, and instead of using IDE, i want to using command line to learn what's running under the hood
I'm following the Getting Started guild on MigLayout
#MigWindow.java
public class MigWindow {
public static void main(){
javax.swing.JPanel panel = new javax.swing.JPanel(new MigLayout());// a simple line to make sure the library jar import correctly
}
}
and compile with these command:
javac -cp ./MigLayout.jar MigWindow.java
and I got a error:
MigWindow.java:3: cannot find symbol
symbol : class MigLayout
location: class MigWindow
javax.swing.JPanel panel = new javax.swing.JPanel(new MigLayout());
^
1 error
It seems the jar library doesn't import correctly, any idea?
~
Make sure you add the import for MigLayout
import net.miginfocom.swing.MigLayout;
It may sound obvious, but make sure MigLayout.jar the current directory when calling javac here and that your JAR file has not been corrupted.
Update:
To check that your JAR file does contain the class you can do:
jar tvf MigLayout.jar
and check for the MigLayout class. Failing to find the class you can download the correct one from here.
You are missing an import statement in your Source File. The compiler does not know where 'MigLayout' is coming from.
Add at the top of your file, but below of your package statement (if any) an import, e.g.
import package.MigLayout;
This tells the compiler what to import from the given class path. You will need to replace package with the correct package.
I have 2 .proto files :
First file:
package com.test.model;
message ProtoModel {
required CustomObj custom=1;
}
Second file:
package com.test.model;
message CustomObj {
required string smth=1;
}
The issue here is that "CustomObj" is said to be "unresolved reference" .
Thus, I've tried to import the second file into first file:
import "com/test/model/firstFile.proto"
package com.test.model;
message ProtoModel {
required CustomObj custom=1;
}
I still get the same issue !!
The import statement is the folder relative to the place where you invoke protoc.
It looks like you have treated it as relative to the package instead.
e.g. if (like me) you store both files in src/main/resources, you'd invoke protoc as follows:
protoc src/main/resources/firstFile.proto src/main/resources/secondFile.proto --java_out=src/generated/java
and your import statement would be import "src/main/resources/firstFile.proto"
If you want to store the files in subfolders according to package name, then you just add this accordingly, after the top-level foldername.
HTH