-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[FLINK-3771] [gelly] Methods for translating Graphs #1900
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
Changes from all commits
2757b2b
2a05832
886b806
9c0e097
ddb4e1e
8e5c4ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.flink.graph.asm.translate; | ||
|
||
import org.apache.flink.api.common.functions.MapFunction; | ||
import org.apache.flink.types.LongValue; | ||
|
||
/** | ||
* Translate {@link LongValue} by adding a constant offset value. | ||
*/ | ||
public class LongValueAddOffset | ||
implements MapFunction<LongValue, LongValue> { | ||
|
||
private final long offset; | ||
|
||
private LongValue output = new LongValue(); | ||
|
||
/** | ||
* Translate {@link LongValue} by adding a constant offset value. | ||
* | ||
* @param offset value to be added to each element | ||
*/ | ||
public LongValueAddOffset(long offset) { | ||
this.offset = offset; | ||
} | ||
|
||
@Override | ||
public LongValue map(LongValue value) | ||
throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be moved to the line above |
||
output.setValue(offset + value.getValue()); | ||
return output; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.flink.graph.asm.translate; | ||
|
||
import org.apache.flink.api.common.functions.MapFunction; | ||
import org.apache.flink.types.IntValue; | ||
import org.apache.flink.types.LongValue; | ||
|
||
/** | ||
* Translate {@link LongValue} to {@link IntValue}. | ||
* | ||
* Throws {@link RuntimeException} for integer overflow. | ||
*/ | ||
public class LongValueToIntValue | ||
implements MapFunction<LongValue, IntValue> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be moved to the line above |
||
|
||
private IntValue output = new IntValue(); | ||
|
||
@Override | ||
public IntValue map(LongValue value) | ||
throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be moved to the line above |
||
long val = value.getValue(); | ||
|
||
if (val > Integer.MAX_VALUE) { | ||
throw new RuntimeException("LongValue input overflows IntValue output"); | ||
} | ||
|
||
output.setValue((int) val); | ||
return output; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.flink.graph.asm.translate; | ||
|
||
import org.apache.flink.api.common.functions.MapFunction; | ||
import org.apache.flink.types.LongValue; | ||
import org.apache.flink.types.StringValue; | ||
|
||
/** | ||
* Translate {@link LongValue} to {@link StringValue}. | ||
*/ | ||
public class LongValueToStringValue | ||
implements MapFunction<LongValue, StringValue> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same :) |
||
|
||
private StringValue output = new StringValue(); | ||
|
||
@Override | ||
public StringValue map(LongValue value) | ||
throws Exception { | ||
output.setValue(Long.toString(value.getValue())); | ||
return output; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can go in the line above