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

feat(Hstore): Hstore support bulkload #630

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions hugegraph-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<version>${lombok.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package org.apache.hugegraph.serializer;

import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.serializer.direct.util.GraphSchema;

public abstract class AbstractGraphElementSerializer implements GraphElementSerializer {
protected HugeClient client;
protected GraphSchema graphSchema;

public AbstractGraphElementSerializer(HugeClient client) {
this.client = client;
this.graphSchema = new GraphSchema(client);
}

public void close() {
this.client.close();
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package org.apache.hugegraph.serializer;

import org.apache.hugegraph.serializer.direct.struct.Directions;
import org.apache.hugegraph.structure.GraphElement;
import scala.Tuple2;

public interface GraphElementSerializer {

Tuple2<byte[], Integer> getKeyBytes(GraphElement e, Directions direction);
byte[] getValueBytes(GraphElement e);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package org.apache.hugegraph.serializer;

import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.serializer.config.SerializerConfig;
import org.apache.hugegraph.serializer.direct.HBaseSerializer;
import org.apache.hugegraph.serializer.direct.HStoreSerializer;

public class SerializerFactory {

public static GraphElementSerializer getSerializer(HugeClient client, SerializerConfig config) {
switch (config.getBackendStoreType()) {
case "hstore":
return new HStoreSerializer(client, config.getVertexPartitions(), config.getGraphName(), config.getPdAddress(), config.getPdRestPort());
case "hbase":
return new HBaseSerializer(client, config.getVertexPartitions(), config.getEdgePartitions());
default:
throw new IllegalArgumentException("Unsupported serializer backend type: " + config.getBackendStoreType());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with this
* work for additional information regarding copyright ownership. The ASF
* licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package org.apache.hugegraph.serializer.config;


import lombok.Data;

@Data
public class SerializerConfig {
private int vertexPartitions;
private int edgePartitions;
private String pdAddress;
private String pdRestPort;
private String graphName;


private String backendStoreType;

public SerializerConfig(int vertexPartitions, int edgePartitions, String pdAddress, String pdRestPort, String graphName) {
this.vertexPartitions = vertexPartitions;
this.edgePartitions = edgePartitions;
this.pdAddress = pdAddress;
this.pdRestPort = pdRestPort;
this.graphName = graphName;
}

public SerializerConfig() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,52 @@
import java.util.Map;

import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.serializer.AbstractGraphElementSerializer;
import org.apache.hugegraph.serializer.direct.struct.Directions;
import org.apache.hugegraph.serializer.direct.struct.HugeType;
import org.apache.hugegraph.serializer.direct.util.BytesBuffer;
import org.apache.hugegraph.serializer.direct.util.GraphSchema;
import org.apache.hugegraph.serializer.direct.util.Id;
import org.apache.hugegraph.serializer.direct.util.IdGenerator;
import org.apache.hugegraph.structure.GraphElement;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.schema.PropertyKey;
import scala.Tuple2;

/**
* TODO: review later
*/
public class HBaseSerializer {
public class HBaseSerializer extends AbstractGraphElementSerializer {

private int edgeLogicPartitions;
private int vertexLogicPartitions;
private HugeClient client;
private GraphSchema graphSchema;


public HBaseSerializer(HugeClient client, int vertexPartitions, int edgePartitions) {
this.client = client;
this.graphSchema = new GraphSchema(client);
super(client);
this.edgeLogicPartitions = edgePartitions;
this.vertexLogicPartitions = vertexPartitions;
}

public byte[] getKeyBytes(GraphElement e) {
@Override
public Tuple2<byte[], Integer> getKeyBytes(GraphElement e, Directions direction) {
byte[] array = null;
if (e.type() == "vertex" && e.id() != null) {
BytesBuffer buffer = BytesBuffer.allocate(2 + 1 + e.id().toString().length());
buffer.writeShort(getPartition(HugeType.VERTEX, IdGenerator.of(e.id())));
buffer.writeShort(getPartition(HugeType.VERTEX, IdGenerator.of(e.id())));
buffer.writeId(IdGenerator.of(e.id()));
array = buffer.bytes();
} else if (e.type() == "edge") {
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
Edge edge = (Edge)e;
Edge edge = (Edge) e;
buffer.writeShort(getPartition(HugeType.EDGE, IdGenerator.of(edge.sourceId())));
buffer.writeId(IdGenerator.of(edge.sourceId()));
buffer.write(HugeType.EDGE_OUT.code());
buffer.writeId(IdGenerator.of(graphSchema.getEdgeLabel(e.label()).id())); //出现错误
buffer.writeId(IdGenerator.of(graphSchema.getEdgeLabel(e.label()).id()));
buffer.writeStringWithEnding("");
buffer.writeId(IdGenerator.of(edge.targetId()));
array = buffer.bytes();
}
return array;
return new Tuple2<>(array, 0);
}

public byte[] getValueBytes(GraphElement e) {
Expand Down
Loading
Loading