Access to Solr parameters from a ValueSource Parser - solr

So I have this class:
public class CustomValueSourceParser extends ValueSourceParser {
#Override
public ValueSource parse(FunctionQParser fqp) throws ParseException {
...
List<ValueSource> valSources = fqp.parseValueSourceList();
String iComeFromTheSolrFunctionArguments =
((LiteralValueSource)valSources.get(0)).getValue();
String iComeFromTheSolrQuery;
return new CustomValueSource(iComeFromTheSolrQuery, iComeFromTheSolrFunctionArguments);
}
}
I'd like to take the variable iComeFromTheSolrQuery from the solr query itself--not from the function arguments (because I will be calling the function multiple times and this string is very large).
Is there a way to do this? I tried adding a field to the search criteria, and then calling fqp.getParams(FIELD_NAME), but nothing came through.
Ideas?

Figured it out. What I wanted was to add a paramater. Not a field. When Formulating the query, I did this:
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(PARAM_NAME_CONSTANT, paramValueString);
solrQuery.add(params);
Then in the above code I got the parameter like this:
public class CustomValueSourceParser extends ValueSourceParser {
#Override
public ValueSource parse(FunctionQParser fqp) throws ParseException {
...
List<ValueSource> valSources = fqp.parseValueSourceList();
String iComeFromTheSolrFunctionArguments =
((LiteralValueSource)valSources.get(0)).getValue();
String iComeFromTheSolrQuery=fqp.getParam(PARAM_NAME_CONSTANT);
return new CustomValueSource(iComeFromTheSolrQuery, iComeFromTheSolrFunctionArguments);
}
}

Related

How can I add message key to KafkaSink in Apache Flink 1.14

As stated in the title I need to set a custom message key in KafkaSink. I cannot find any indication on how to achieve this in the Apache Flink 1.14 docs.
At the moment I'm correctly setting up the KafkaSink and the data payload is correctly written in the topic, but the key is null.
Any suggestions? Thanks in advance
You should implement a KafkaRecordSerializationSchema that sets the key on the ProducerRecord returned by its serialize method.
You'll create the sink more-or-less like this:
KafkaSink<UsageRecord> sink =
KafkaSink.<UsageRecord>builder()
.setBootstrapServers(brokers)
.setKafkaProducerConfig(kafkaProps)
.setRecordSerializer(new MyRecordSerializationSchema(topic))
.setDeliverGuarantee(DeliveryGuarantee.EXACTLY_ONCE)
.setTransactionalIdPrefix("my-record-producer")
.build();
and the serializer will be something like this:
public class MyRecordSerializationSchema implements
KafkaRecordSerializationSchema<T> {
private static final long serialVersionUID = 1L;
private String topic;
private static final ObjectMapper objectMapper =
JsonMapper.builder()
.build()
.registerModule(new JavaTimeModule())
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
public MyRecordSerializationSchema() {}
public MyRecordSerializationSchema(String topic) {
this.topic = topic;
}
#Override
public ProducerRecord<byte[], byte[]> serialize(
T element, KafkaSinkContext context, Long timestamp) {
try {
return new ProducerRecord<>(
topic,
null, // choosing not to specify the partition
element.ts.toEpochMilli(),
element.getKey(),
objectMapper.writeValueAsBytes(element));
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(
"Could not serialize record: " + element, e);
}
}
}
Note that this example is also setting the timestamp.
FWIW, this example comes from https://github.com/alpinegizmo/flink-mobile-data-usage/blob/main/src/main/java/com/ververica/flink/example/datausage/records/UsageRecordSerializationSchema.java.
This example is for scala programmers. Here, we are defining a key by generating UUID for each events.
import org.apache.flink.connector.kafka.sink.KafkaRecordSerializationSchema
import org.apache.kafka.clients.producer.ProducerRecord
import java.lang
class MyRecordSerializationSchema extends KafkaRecordSerializationSchema[String] {
override def serialize(element: String, context: KafkaRecordSerializationSchema.KafkaSinkContext, timestamp: lang.Long): ProducerRecord[Array[Byte], Array[Byte]] = {
return new ProducerRecord(
kafkaTopicName,
java.util.UUID.randomUUID.toString.getBytes,
element.getBytes
)
}
}
In the main class, will have to pass an instance of this class while defining the kafka sink like this:
val sinkKafka: KafkaSink[String] = KafkaSink.builder()
.setBootstrapServers(bootstrapServerUrl) //Bootstrap server url
.setRecordSerializer(new MyRecordSerializationSchema())
.build()

java.lang.AssertionError: java.lang.NullPointerException when trying to use getdata

I'm getting java.lang.AssertionError: java.lang.NullPointerException
Below is my code. trying to pass data from excel to a textbox. Please help (I'm calling the below method from another test)
public class myclass extends class1
{
public WebElement single = driver.findElement(By.xpath("//input[#id='IDSingle']"));
public myclass(ScriptHelper scriptHelper)
{
super(scriptHelper);
if(!driver.getTitle().contains("My Page"))
{
throw new IllegalStateException("My page expected, but not displayed!");
}
}
public void mytest()
{
driver.manage().timeouts().implicitlyWait(11,TimeUnit.SECONDS);
String sng=dataTable.getData("RMSeatPage Data", "Single");
System.out.println(sng);
single.sendKeys(sng);
}
}

React Js and Spring boot faster xml jackson databin

Hello when i try to get all values with this path : localhost:8080/aspsort/all
i get error :
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:166) ~[jackson-databind-2.10.3.jar:2.10.3]
the method is :
#GetMapping("/all")
public Iterable<Rfpobject> getallRFP()
{
return rfprepo.findAll();
}
instead of Iterable try changing it to List as return type .
and in rfprepo interface add this
#Override
List<Data> findAll();
example
#Autowired
RfpRepository rfprepo;
#GetMapping("/all")
public Iterable<Rfpobject> getallRFP()
{
return rfprepo.findAll();
}
public interface RfpRepository extends CrudRepository<Rfpobject, Long> {
#Override
List<Rfpobject> findAll();
}
let me know if this solved your issue.

Salesforce apex class Unexpected token error

I want to create a keyword search referring to "UserName__c" api on Salesforce Apex class.
compile error Unexpected token 'UserName__c'.
public with sharing class AccountListCon {
static List<String> TARGET_FIELDS = new List<String>{
'Name'
,'UserName__c'
,'CompanyName__c'
};
public SearchCondition condition{ get;set; }
public String UserName__c results { get;set; }
public String sortingField { get;set; }
public void init(){
this.condition = new SearchCondition();
this.results = new String UserName__c();
}
public PageReference clear(){
init();
return null;
}
There is no such type String UserName__c. It's not entirely clear what you want to do here, but I suspect you intend just to declare a String variable. The fact that you're looking for values in some field whose API name is UserName__c is not relevant to the type system
public String UserName__c results { get;set; } is wrong. Is this supposed to be just
public String results { get;set; } ?

Mixin annotation not getting honored when passed as a parameter

I have a third party class SpecialObject as:
public class SpecialObject {
private String name;
private Integer id;
private Date date;
public String getFoo() {return "foo";} //Outlier
public String getName() { return name;}
public Integer getId() {return id;}
public Date getDate() {return date;}
public void setName(String name) {this.name = name;}
public void setId(Integer id) {this.id = id;}
public void setDate(Date date) {this.date = date;}
}
I wish to only project out name and date properties when serializing it. Using the magic of MixinAnnotation from Jackson, I created a Mixin interface as:
#JsonAutoDetect(getterVisibility = Visibility.NONE)
public interface SpecialObjectMixin {
#JsonProperty
public String getName();
#JsonProperty
public Date getDate();
}
In order to facilitate handling of this SpecialObject as parameter, I have also defined a SpecialObjectHandler which implements the fromString() method.
#Override
public SpecialObject fromString(String json) {
try {
return objectMapper.readValue(json, SpecialObject.class);
} catch (IOException exception) {
throw new IllegalArgumentException("Unable to write JSON output",
exception);
}
}
When the deserializer invokes this method, the objectMapper throws an error as
Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "foo" (Class com.kilo.SpecialObject), not marked as ignorable
at [Source: java.io.StringReader#2d2217da; line: 1, column: 60] (through reference chain: com.kilo.SpecialObject["foo"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2732)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1863)
at com.kilo.SpecialObjectHandler.fromString(SpecialObjectHandler.java:34)
My question is that is there a way that I can have the objectMapper (org.codehaus.jackson.map.ObjectMapper) also honor annotations from the Mixin where I had configured it to only deal with name and date? Feel free to point out something elementary that I may have overlooked. Thanks in advance!
It was a problem with configuration. The mixin was only set on the serialization config and not on the deserialization config causing the issue. Setting it on both configs solves the problem.

Resources