Apache Pig : UDF : ERROR 1003: Unable to find an operator for alias fileterd - apache-pig

Wrote a custom UDF in pig by name vaidateUser which validates usernames.
public class ValidateUser extends FilterFunc {
public Boolean exec(Tuple tuple) throws IOException {
// custom validation code
}
}
The class is a part of default package and is part of pig_udfs.jar.
This JAR is used in the pig script : validateUsers.pig
REGISTER 'pig_udfs.jar';
users = load 'users.txt' using PigStorage(',') as (user:chararray);
validUsers = filter users by ValidateUser(user);
dump validUsers;
Tried executing the script using :
pig -x local validateusers.pig
Getting error as below, any inputs/ thoughts on resolving this would be appreciated !
Pig Stack Trace:
ERROR 1003: Unable to find an operator for alias fileterd
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1003: Unable to find an operator for alias fileterd
at org.apache.pig.PigServer.openIterator(PigServer.java:732)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:615)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:303)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:168)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:144)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:90)
at org.apache.pig.Main.run(Main.java:500)
at org.apache.pig.Main.main(Main.java:107)

I didn't face any issue the custom filter UDF and its working fine, Can you try this?.
In the below example, i will filter out all the names which is not equal to "test".
users.txt
test
mike
test
john
PigScript:
REGISTER 'pig_udfs.jar';
users = load 'users.txt' using PigStorage(',') as (user:chararray);
validUsers = filter users by ValidateUser(user);
dump validUsers;
ValidateUser.java
import java.io.IOException;
import org.apache.pig.FilterFunc;
import org.apache.pig.data.Tuple;
public class ValidateUser extends FilterFunc {
#Override
public Boolean exec(Tuple input) throws IOException {
try {
String str = (String)input.get(0);
return (!str.equals("test"));
}
catch (IOException ee) {
throw ee;
}
}
}
Output:
(john)
(mike)
Makesure that you have set piggybank.jar in the classpath
> javac ValidateUser.java
> jar -cvf pig_udfs.jar ValidateUser.class
> pig -x local validateusers.pig

Related

How could i inherit a class using github.parser without deprication warrings

I am using Com.GitHub.java parser for generating java code. i am facing a problem for generating extends keywords
This line "extendsList.add(new ClassOrInterfaceType("CustomEndpointResource"));".
This statement is showing deprecated .that means it gives a warning.
How can i avoid this warning ? So, i can not use this statement. any alternative
way other than this deprecated statement (extendsList.add(new ClassOrInterfaceType).
My Source code:
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Modifier;
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.expr.StringLiteralExpr;
import com.github.javaparser.ast.type.ClassOrInterfaceType;
​
public class ProductCreate2 {
​
public static void main(String[] args) {
CompilationUnit compilationUnit = new CompilationUnit();
compilationUnit.setPackageDeclaration("org.meveo.mymodule.resource");
compilationUnit.addImport("java.util", false, true);
ClassOrInterfaceDeclaration restEndpointClass = compilationUnit.addClass("ProductCreate",Modifier.Keyword.PUBLIC);
restEndpointClass.addSingleMemberAnnotation("Path",new StringLiteralExpr("myproduct"));
restEndpointClass.addMarkerAnnotation("RequestScoped");
var injectedfield=restEndpointClass.addField("CreateMyProduct", "CreateMyProduct", Modifier.Keyword.PRIVATE);
injectedfield.addMarkerAnnotation("Inject");
NodeList<ClassOrInterfaceType> extendsList = new NodeList<>();
extendsList.add(new ClassOrInterfaceType("CustomEndpointResource"));
restEndpointClass.setExtendedTypes(extendsList);
​
System.out.println(compilationUnit);
​
}
}
Expected output of my code:
class productCreate extends ABC
{
}
There can be multiple ways to avoid using the deprecated constructor. E.g. you can use the following instead:
ClassOrInterfaceType extendClass = new ClassOrInterfaceType();
extendClass.setName(new SimpleName("CustomEndpointResource"));
extendsList.add(extendClass);
i am facing another problem for generating this annotation line : #Path("/{uuid}").
Expected output of my code:
class productGet {
#Path("/{uuid}")
public Response getProduct() throws ServletException {
}
}

TestNG DataProvider marks as invalid return type Iterator<CustomObject>, but it passes the params into a test method

When creating a Dataprovider that returns Iterator I have it in my test method, but my intellij-idea marks this return type as invalid and shows the message:
"Data provider must return either Object[][] or Iterator[], or Iterator".
Here is my class/ method:
public class TradeTestDataProvider {
#DataProvider(name = "experimental")
public Iterator<TestCase> createCases() throws IOException {
List<TestCase> test = DataReader.generateCasesFromJson("src/test/resources/json/experimental_test_case");
return test.iterator();
}
}
Please advise, if I am missing something or it is related to TestNG/IDE issue?
Update:
I created a post to discuss this issue with plugin:
topic

Cucumber- // Write code here that turns the phrase above into concrete actions

I Tried to execute the same test with different data but I am getting the following error when I tried to run the test
You can implement missing steps with the snippets below:
#When("^Enter the ADMIN and password(\\d+)$")
public void enter_the_ADMIN_and_password(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Below is my Feature file
Scenario Outline: Login
Given Open chrome and login
When Enter the <Username> and <Password>
Then Click on Login
Examples:
|Username |Password |
|ADMIN |password123|
Below is the #when annotation part in Steps file
#When("^Enter the \"(.*)\" and \"(.*)\"$")
public void enter_the_Username_and_Password(String username,String Password) throws Throwable
{
System.out.println("This step enter the Username and Password on the login page."+username +Password);
loginObj.Login(driver);
}
It may be occurring due to cucumbers packages is misconfigured. Check the GLUE options
#RunWith(Cucumber.class)
#CucumberOptions(
features = { "src/test/resources/features/CucumberTests.feature" },
tags = { "#integration_test"},
glue = { "br.com.cucumber.integration.stepDefinition" },
format = { "pretty", "html:target/reports/cucumber/html", "json:target/cucumber.json", "usage:target/usage.jsonx", "junit:target/junit.xml" })
#ContextConfiguration(classes= AppConfiguration.class)
public class CumcumberTest extends BaseTestCase {
}
I think what you are describing as an "error" is in fact cucumber telling you that is not able to find the matching definition for the step "When Enter the Username and Password" and has auto-generated the example definition below based on the scenario outline data:
#When("^Enter the ADMIN and password(\\d+)$")
public void enter_the_ADMIN_and_password(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
The problem is that your step definition is using quotes on the parameters but your actual step has no quotes, hence cucumber is not able to match them. You either need to change your step in the feature file to include quotes:
When Enter the "<Username>" and "<Password>"
Or you need to change the step definition to not include quotes:
#When("^Enter the (.*) and (.*)$")
public void enter_the_Username_and_Password(String username,String Password) throws Throwable
{
System.out.println("This step enter the Username and Password on the login page."+username +Password);
loginObj.Login(driver);
}
I got the same error. For me the problem was that I created step definition in the package for back end tests instead of front end ones. If the step definition classes have same or similar names, it is possible to make a mistake. This would happen during chosing the wrong package while creating step definition from the feature file in Intellij.
I was getting this issue and discovered the reason was I accidentally gave the name of the class and not the package for the glue code:
The wrong argument value for my gluecode was my class as: gluecode="StepDefinition", when it should have been my package: gluecode="stepDefs"
My TestRunner.java looks as follows:
package testRunner;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(
features = "src/test/java/features",
glue = "stepDefs")
public class TestRunner {
}
I got the same error. In my case I was forgetting the .step. part in my file name.
So I've solved by modifying my file name from:
mystepfile.ts
to:
mystepfile.step.ts

Create data property XSD:string with Jena

the problem sounds so simple: I would like to create an data property for an individual as XSD:string in my ontology.
I can create properties of XSD:DateTime, XSD:Float or XSD:int, but if I use XSD:string, I get a untyped property!
I created a minimal example, which create an ontology with one class, one individual an two data properties. A DateTime, which works like expected and one string, which has no type in the ontology.
I tried with Jena versions 3.4 and 3.0.1 and have no idea who to fix it.
package dataproperty;
import java.io.FileOutputStream;
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
public class DataProperty {
public static void main(String[] args) throws Exception {
OntModel model = ModelFactory.createOntologyModel();
String OWLPath = "DataProp.owl";
try{
String NS = "http://www.example.org/ontology.owl#";
//Create Ontology
model.createClass(NS+"Test");
Resource r = model.createResource(NS+"Test");
model.createIndividual(NS+"Indi1", r);
r = model.createResource(NS+"Indi1");
model.createDatatypeProperty(NS+"Name");
model.createDatatypeProperty(NS+"Date");
//Add Data Properties
Property p = model.getProperty(NS+"Name");
model.add(r, p, ResourceFactory.createTypedLiteral("MyName", XSDDatatype.XSDstring));
p = model.getProperty(NS+"Date");
model.add(r, p, ResourceFactory.createTypedLiteral("2017-08-12T09:03:40", XSDDatatype.XSDdateTime));
//Store the ontology
FileOutputStream output = null;
output = new FileOutputStream(OWLPath);
model.write(output);
}catch (Exception e) {
System.out.println("Error occured: " + e);
throw new Exception(e.getMessage());
}
}
}
It is not untyped in RDF 1.1 - it's written in short form (better compatibility).
e.g.
https://www.w3.org/TR/turtle/
Section 2.5.1
"If there is no datatype IRI and no language tag, the datatype is xsd:string."

NHibernate: Could not create the driver from Test.SqlServerCeDriver_ImageFix

Im trying to resolve an issue where when using NHibernate with a SqlServerCeDriver that uses an image column you receive an error: "Byte array truncation to a length of 8000.". I found the following solution:
http://mgeorge-notes.blogspot.com/2009/05/nhibernate-mapping-from-binary-to.html
And created the following class:
namespace Test
{
public class SqlServerCeDriver_ImageFix : SqlServerCeDriver
{
protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);
if (sqlType is BinarySqlType)
{
PropertyInfo dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType");
dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null);
}
}
}
}
But when I change the NHibernate mapping from
NHibernate.Driver.SqlServerCeDriver
to
Test.SqlServerCeDriver_ImageFix
I get the error, but I am not sure why.
The inner exception is: "Could not load type Test.SqlServerCeDriver. Possible cause: no assembly name specified."
Anyone have any ideas as to what im doing wrong?
When defining the driver in the config, define it with the AssemblyQualifiedName, i.e.:
Test.SqlServerCeDriver_ImageFix, MyAssemblyThatContainsThisType