Kafka state store range query - apache-kafka-streams

How to specify range query to get the details from the state store in the kafka. I thought it is based on ASCII value but when I tried this not getting expected result.Could someone help me to solve this issue
Details: Key will be always a String.
String fromRange = String.format("%s", prefix, "NUL");
String toRange = String.format("%s%s", prefix, "~");
list = store.range(fromRange, toRange);

Related

Can I change the numbered tags in a proto file?

This post describes what the numbered tags in proto files are for, essentially match fields when serializing and deserializing the data. My question is: what happens if I change the number of an existing field?
Taking the same example, say this is the original data
message SearchRequest {
required string query = 1;
// Pagination fields
optional int32 page_number = 2;
optional int32 result_per_page = 3;
}
And I want to add a new field, which logically makes sense to put before the pagination fields - Can I re-enumerate the fields as below, if I'm not using the page_number and result_per_page fields yet (though the message type SearchRequest is in use)?
message SearchRequest {
required string query = 1;
optional int32 new_data = 2;
// Pagination fields
optional int32 page_number = 3;
optional int32 result_per_page = 4;
}
Should I have given the pagination fields higher numbers from the start to allow for new fields?
The documentation says
These field numbers are used to identify your fields in the message
binary format, and should not be changed once your message type is in
use.
Changing field numbers is almost always a bad idea - you will get very odd behaviour unless all clients and servers are.deployed at exactly the same time and there is no persisted payload data anywhere (in files, databases, etc). In particular, the serializer will try to interpret data as a different thing: in some cases this will cause a serialization failure and in other cases it will silently and happily deserialize the data with garbage meaning, causing chaos.
There is no reason not to simply use field 5.

The result of elasticsearch using jest api has double quotes("value") but I want to get just value for sure

guys.
I've struggled with something really weird. I want to get the result of Elasticsearch query, data(inside source). So this is a part of my code.
SearchResult result = jestClient.execute(search);
JsonObject json = result.getJsonObject();
Map<String, String> map = new HashMap<>();
for (JsonElement jsonElement : json.getAsJsonObject("hits").getAsJsonArray("hits")) {
JsonObject _source = jsonElement.getAsJsonObject().get("_source").getAsJsonObject();
String orderNumber = _source.get("orderNumber").toString();
String equipmentCode = _source.get("equipmentCode").toString();
map.put(orderNumber, equipmentCode);
}
The thing is the value of orderNumber is "ABCDE". What I expected is ABCDE. (To make it clear, both String contain the double quotes with the value... The funny thing is shown in the debug mode.
I've just checked the values in _source, it has the first value of String "A" still... but the first value of orderNumber is """ and the second value is "A"... I don't know how to resolve this and anyone helping me?
I'm answering for myself and ppl who will have the same problem. I should have used getAsString() instead of toString()... hope that I saved your time

Filter records using Linq on an Enum type

I'm hoping this is a simple solution. I have a field (PressType) in a table (Stocks) that is seed populated by using an Enum. The table stores the data as an integer. However when I want to query some data via Linq it gives me issues. I can filter any other fields in the table using this format however on the Enum populated field it says
the "==" operator cannot be applied to operands of type "Models.PressType" and "string".
Any help you could give would be appreciated, thanks.
var test = db.Stocks.Where(x => x.PressType == myValue);
There is nothing wrong with your Linq. Your problem is that myValue is of type string. You need to convert your string to the enum first.
string myValue = SomeControl.Text;
Models.PressType myValueAsEnum = (Models.PressType)
Enum.Parse(typeof(Models.PressType), myValue);
IQueryable<Stock> test = db.Stocks.Where(x => x.PressType == myValueAsEnum);

Getting value of database field in Crystal Reports

Currently I'm working on legacy application, that uses crystal report engine. I have to get value of database fields programmatically. As I've assumed, I need proper event for getting next code to work:
Report.Database.Tables(1).Fields(1).Value
But the value is always empty in DownloadStarted/Finished event handlers. What I'm doing wrong and is it at least possible?
I think that if you want to get value of your table fields in program the best way is that you get the field name from report and then connect to your table directly and use report field names as the table columns name
i do it in c# i hope it can help you in vb6 too:
string name = report2.Database.Tables[1].Fields[1].Name;
string[] names = name.Split('.');
and then add your database to your program and use names like this:
DataTable dt = new DataTable();
string[] value = dt.Columns[names[1]];
if you just need your tables values, you can use my last answer, but if you need value of database fields in crystal report, i mean something like formula field ,this code can help you:
CRAXDRT.FormulaFieldDefinitions definitions = report2.FormulaFields;
string formulaText = "IF " + report2.Database.Tables[1].Fields[3].Name
+ " > 10 THEN" + report2.Database.Tables[1].Fields[2].Name;
definitions.Add("Test", formulaText);
report2.Sections[1].AddFieldObject(definitions[1], 0, 0);

How to find a template in Alfresco with OpenCMIS from Spring application?

I am working in a Spring 3.1 application and I need to find a String template document located in Alfresco's repository. I can already create a file in alfresco with OpenCMIS, but I couldn't figure out how to find a template, so if anyone knows how to do it or point me an example, please let me know, thanks in advance!
There are a number of options you can use. First of all, you need to have a criteria that uniquely identifies your document. Here below I'll show some, hopefully your case falls in one of them or they will inspire you towards a proper solution. The following uses pseudo code, please have a look to the OpenCMIS dev guide for working with the Java client API.
BY ID
Once you create a Document via CMIS, you get the unique ID of it that you can store in your application for later retrieval.
Map<String, Object> templateProperties = createDocumentProperties();
Folder folder = getTemplatesFolder();
ObjectId templateId = createTemplateIn(folder);
storeTemplateId(templateId.getId(), templateProperties); // persist the ID
...
// later on
...
String id = getTemplateId(); // retrieve the ID
Session session = openCMISSession();
Document template = (Document)session.getObject(id);
BY PATH
Similar to the previous example, you will have to take note of where you stored the document instead of its ID, or having a way to construct the path by hand.
String path = getTemplatePath(); // either recover it from DB or construct a path
Document template = (Document)session.getObjectByPath(path);
BY PROPERTY VALUE
Let's say you can use a specific metadata field on a template Document that allows you to easily retrieve it afterwards (e.g. you created some specific Alfresco metadata model for your use case).
String meta = TemplateProperties.TEMPLATE_ID; // e.g. my:templateId
String type = TemplateProperties.TEMPLATE_TYPE; // e.g. my:template
String templateMeta = "TEMPLATE1";
Map<String, Object> templateProperties = createDocumentProperties();
templateProperties.put(meta, templateMeta);
templateProperties.put(PropertyIds.OBJECT_TYPE_ID, type);
createTemplate(templateProperties);
...
// later on
...
String type = TemplateProperties.TEMPLATE_TYPE; // e.g. my:template
String meta = TemplateProperties.TEMPLATE_ID;
String tplId = "TEMPLATE1";
String query = String.format("SELECT * FROM % WHERE % = '%'", type, meta, tplId);
ItemIterable<QueryResult> i = session.query(query, false);
QueryResult qr = i.iterator().next(); // let's assume we have one single match
String templateId = qr.getPropertyByQueryName("cmis:objectId").getFirstValue()
Document template = (Document)session.getObject(templateId);
BY QUERY
The previous approach is not really tied to search by property name, and can be easily extended to use any kind of query that identifies your templates. Have a look at the Alfresco page on its CMIS query language implementation details to learn more ways of querying the repository.

Resources