Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add config for whether encoding number of primary keys #1323

Merged
merged 4 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,15 @@ public static synchronized CoreOptions instance() {
5000
);

public static final ConfigOption<Boolean> VERTEX_ENCODE_PK_NUMBER =
new ConfigOption<>(
"vertex.encode_primary_key_number",
"Whether to encode number value of primary key " +
"in vertex id.",
disallowEmpty(),
true
);

public static final ConfigOption<Boolean> QUERY_IGNORE_INVALID_DATA =
new ConfigOption<>(
"query.ignore_invalid_data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,16 @@ private <V> boolean checkDataType(Collection<V> values) {
return valid;
}

public <V> Object serialValue(V value) {
public <V> Object serialValue(V value, boolean encodeNumber) {
V validValue = this.validValue(value);
E.checkArgument(validValue != null,
"Invalid property value '%s' for key '%s'",
value, this.name());
E.checkArgument(this.cardinality.single(),
"The cardinality can't be '%s' for navigation key '%s'",
this.cardinality, this.name());
if (this.dataType.isNumber() || this.dataType.isDate()) {
if (encodeNumber &&
(this.dataType.isNumber() || this.dataType.isDate())) {
return LongEncoding.encodeNumber(validValue);
}
return validValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public List<Object> sortValues() {
HugeProperty<?> property = this.getProperty(sk);
E.checkState(property != null,
"The value of sort key '%s' can't be null", sk);
propValues.add(property.serialValue());
propValues.add(property.serialValue(true));
}
return propValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public V value() throws NoSuchElementException {
return this.value;
}

public Object serialValue() {
return this.pkey.serialValue(this.value);
public Object serialValue(boolean encodeNumber) {
return this.pkey.serialValue(this.value, encodeNumber);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import com.baidu.hugegraph.backend.query.QueryResults;
import com.baidu.hugegraph.backend.serializer.BytesBuffer;
import com.baidu.hugegraph.backend.tx.GraphTransaction;
import com.baidu.hugegraph.config.CoreOptions;
import com.baidu.hugegraph.config.HugeConfig;
import com.baidu.hugegraph.perf.PerfUtil.Watched;
import com.baidu.hugegraph.schema.EdgeLabel;
import com.baidu.hugegraph.schema.PropertyKey;
Expand Down Expand Up @@ -200,12 +202,14 @@ public List<Object> primaryValues() {
IdStrategy.PRIMARY_KEY);

List<Object> propValues = new ArrayList<>(primaryKeys.size());
boolean encodeNumber = ((HugeConfig) this.graph().configuration()).get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't call configuration() if enable auth

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add method graph.option(CoreOptions.VERTEX_ENCODE_PK_NUMBER) and set whitelist

CoreOptions.VERTEX_ENCODE_PK_NUMBER);
for (Id pk : primaryKeys) {
HugeProperty<?> property = this.getProperty(pk);
E.checkState(property != null,
"The value of primary key '%s' can't be null",
this.graph().propertyKey(pk).name());
propValues.add(property.serialValue());
propValues.add(property.serialValue(encodeNumber));
}
return propValues;
}
Expand Down