QueryableStateClient getKVState

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

QueryableStateClient getKVState

Sandeep khanzode
Hi,

I have a stream that exposes the state for Queryable State.

I am using the key as follows:

public class MyKey {
private Long first;
private EnumType myType;
private Long second;

    private TreeMap<String, String> map;
    @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyKey that = (MyKey) o;
boolean isEqual = first.longValue() == that.first.longValue() &&
myTime.name().equalsIgnoreCase(that.myTime.name()) &&
second.longValue() == that.second.longValue();// &&
// map.equals(that.dimensions);
return isEqual;
}

@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (myType != null ? myType.name().hashCode() : 0);
result = 31 * result + (second != null ? second.hashCode() : 0);
// result = 31 * result + (map != null ? map.hashCode() : 0);
return result;
}
}


If I only set the first three members for the key class, then the key lookup works correctly.

If I add the TreeMap, then the lookup always errors with the message; “No state found for the given key/namespace”.

What am I dong wrong with the TreeMap as a member in the Key class for equals/hashcode?

Thanks,
Sandeep
Reply | Threaded
Open this post in threaded view
|

Re: QueryableStateClient getKVState

Matthias
Hi Sandeep,
the equals method does not compare the this.map with that.map but that.dimensions. ...at least in your commented out code. Might this be the problem?

Best,
Matthias

On Tue, Mar 23, 2021 at 5:28 AM Sandeep khanzode <[hidden email]> wrote:
Hi,

I have a stream that exposes the state for Queryable State.

I am using the key as follows:

public class MyKey {
private Long first;
private EnumType myType;
private Long second;

    private TreeMap<String, String> map;
    @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyKey that = (MyKey) o;
boolean isEqual = first.longValue() == that.first.longValue() &&
myTime.name().equalsIgnoreCase(that.myTime.name()) &&
second.longValue() == that.second.longValue();// &&
// map.equals(that.dimensions);
return isEqual;
}

@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (myType != null ? myType.name().hashCode() : 0);
result = 31 * result + (second != null ? second.hashCode() : 0);
// result = 31 * result + (map != null ? map.hashCode() : 0);
return result;
}
}


If I only set the first three members for the key class, then the key lookup works correctly.

If I add the TreeMap, then the lookup always errors with the message; “No state found for the given key/namespace”.

What am I dong wrong with the TreeMap as a member in the Key class for equals/hashcode?

Thanks,
Sandeep
Reply | Threaded
Open this post in threaded view
|

Re: QueryableStateClient getKVState

Sandeep khanzode
Hi Matthias,

Thanks. But yes, I am comparing map with that.map … the comment is probably for the previous variable name.

I can use String, Int, Enum, Long type keys in the Key that I send in the Query getKvState … but the moment I introduce a TreeMap, even though it contains a simple one entry String, String, it doesn’t work … 

Thanks,
Sandeep

On 23-Mar-2021, at 7:00 PM, Matthias Pohl <[hidden email]> wrote:

Hi Sandeep,
the equals method does not compare the this.map with that.map but that.dimensions. ...at least in your commented out code. Might this be the problem?

Best,
Matthias

On Tue, Mar 23, 2021 at 5:28 AM Sandeep khanzode <[hidden email]> wrote:
Hi,

I have a stream that exposes the state for Queryable State.

I am using the key as follows:

public class MyKey {
private Long first;
private EnumType myType;
private Long second;

    private TreeMap<String, String> map;
    @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyKey that = (MyKey) o;
boolean isEqual = first.longValue() == that.first.longValue() &&
myTime.name().equalsIgnoreCase(that.myTime.name()) &&
second.longValue() == that.second.longValue();// &&
// map.equals(that.dimensions);
return isEqual;
}

@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (myType != null ? myType.name().hashCode() : 0);
result = 31 * result + (second != null ? second.hashCode() : 0);
// result = 31 * result + (map != null ? map.hashCode() : 0);
return result;
}
}


If I only set the first three members for the key class, then the key lookup works correctly.

If I add the TreeMap, then the lookup always errors with the message; “No state found for the given key/namespace”.

What am I dong wrong with the TreeMap as a member in the Key class for equals/hashcode?

Thanks,
Sandeep

Reply | Threaded
Open this post in threaded view
|

Re: QueryableStateClient getKVState

Matthias
Could you provide the full stacktrace of your error? That might help me to dig into the code.

Matthias

On Tue, Mar 23, 2021 at 2:33 PM Sandeep khanzode <[hidden email]> wrote:
Hi Matthias,

Thanks. But yes, I am comparing map with that.map … the comment is probably for the previous variable name.

I can use String, Int, Enum, Long type keys in the Key that I send in the Query getKvState … but the moment I introduce a TreeMap, even though it contains a simple one entry String, String, it doesn’t work … 

Thanks,
Sandeep

On 23-Mar-2021, at 7:00 PM, Matthias Pohl <[hidden email]> wrote:

Hi Sandeep,
the equals method does not compare the this.map with that.map but that.dimensions. ...at least in your commented out code. Might this be the problem?

Best,
Matthias

On Tue, Mar 23, 2021 at 5:28 AM Sandeep khanzode <[hidden email]> wrote:
Hi,

I have a stream that exposes the state for Queryable State.

I am using the key as follows:

public class MyKey {
private Long first;
private EnumType myType;
private Long second;

    private TreeMap<String, String> map;
    @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyKey that = (MyKey) o;
boolean isEqual = first.longValue() == that.first.longValue() &&
myTime.name().equalsIgnoreCase(that.myTime.name()) &&
second.longValue() == that.second.longValue();// &&
// map.equals(that.dimensions);
return isEqual;
}

@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (myType != null ? myType.name().hashCode() : 0);
result = 31 * result + (second != null ? second.hashCode() : 0);
// result = 31 * result + (map != null ? map.hashCode() : 0);
return result;
}
}


If I only set the first three members for the key class, then the key lookup works correctly.

If I add the TreeMap, then the lookup always errors with the message; “No state found for the given key/namespace”.

What am I dong wrong with the TreeMap as a member in the Key class for equals/hashcode?

Thanks,
Sandeep

Reply | Threaded
Open this post in threaded view
|

Re: QueryableStateClient getKVState

Sandeep khanzode
It seems that the record exists for that Key (which has the TreeMap member) but there is some equals/hashcode issue in comparing and determining match … maybe the serializedKey byte[] for TreeMap works differently?



On 23-Mar-2021, at 7:23 PM, Matthias Pohl <[hidden email]> wrote:

Could you provide the full stacktrace of your error? That might help me to dig into the code.

Matthias

On Tue, Mar 23, 2021 at 2:33 PM Sandeep khanzode <[hidden email]> wrote:
Hi Matthias,

Thanks. But yes, I am comparing map with that.map … the comment is probably for the previous variable name.

I can use String, Int, Enum, Long type keys in the Key that I send in the Query getKvState … but the moment I introduce a TreeMap, even though it contains a simple one entry String, String, it doesn’t work … 

Thanks,
Sandeep

On 23-Mar-2021, at 7:00 PM, Matthias Pohl <[hidden email]> wrote:

Hi Sandeep,
the equals method does not compare the this.map with that.map but that.dimensions. ...at least in your commented out code. Might this be the problem?

Best,
Matthias

On Tue, Mar 23, 2021 at 5:28 AM Sandeep khanzode <[hidden email]> wrote:
Hi,

I have a stream that exposes the state for Queryable State.

I am using the key as follows:

public class MyKey {
private Long first;
private EnumType myType;
private Long second;

    private TreeMap<String, String> map;
    @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MyKey that = (MyKey) o;
boolean isEqual = first.longValue() == that.first.longValue() &&
myTime.name().equalsIgnoreCase(that.myTime.name()) &&
second.longValue() == that.second.longValue();// &&
// map.equals(that.dimensions);
return isEqual;
}

@Override
public int hashCode() {
int result = first != null ? first.hashCode() : 0;
result = 31 * result + (myType != null ? myType.name().hashCode() : 0);
result = 31 * result + (second != null ? second.hashCode() : 0);
// result = 31 * result + (map != null ? map.hashCode() : 0);
return result;
}
}


If I only set the first three members for the key class, then the key lookup works correctly.

If I add the TreeMap, then the lookup always errors with the message; “No state found for the given key/namespace”.

What am I dong wrong with the TreeMap as a member in the Key class for equals/hashcode?

Thanks,
Sandeep