Skip to content

Commit 547e73d

Browse files
committed
Remove inheritance from ArrowSupport classes
1 parent 341af83 commit 547e73d

File tree

7 files changed

+31
-61
lines changed

7 files changed

+31
-61
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/arrow/vector/VectorToArrowArrayNode.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public abstract class VectorToArrowArrayNode extends PNodeWithContext {
6262

6363
public abstract ArrowArray execute(Node inliningTarget, Object vector);
6464

65-
@Specialization(guards = "arrowVectorSupport.isFixedWidthVector(vector)")
65+
@Specialization(guards = "ctx.arrowVectorSupport.isFixedWidthVector(vector)")
6666
static ArrowArray doIntVector(Node inliningTarget, Object vector,
6767
@Bind("getContext(inliningTarget)") PythonContext ctx,
68-
@Bind("ctx.arrowVectorSupport") ArrowVectorSupport arrowVectorSupport,
6968
@CachedLibrary(limit = "3") InteropLibrary interopLib) {
7069
var snapshot = new ArrowArray.Snapshot();
7170
var unsafe = ctx.getUnsafe();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/arrow/ArrowSupport.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,26 @@
4343
import com.oracle.graal.python.nodes.arrow.capsule.ArrowArrayCapsuleDestructor;
4444
import com.oracle.graal.python.nodes.arrow.capsule.ArrowSchemaCapsuleDestructor;
4545
import com.oracle.graal.python.nodes.arrow.release_callback.ArrowSchemaReleaseCallback;
46+
import com.oracle.graal.python.nodes.arrow.vector.VectorArrowArrayReleaseCallback;
4647
import com.oracle.graal.python.runtime.PythonContext;
4748
import com.oracle.graal.python.util.PythonUtils;
4849
import com.oracle.truffle.api.CompilerAsserts;
4950
import com.oracle.truffle.api.CompilerDirectives;
5051
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5152
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5253
import com.oracle.truffle.api.interop.InteropLibrary;
54+
import com.oracle.truffle.api.source.Source;
5355
import com.oracle.truffle.nfi.api.SignatureLibrary;
5456

55-
public class ArrowSupport extends AbstractArrowSupport {
57+
import static com.oracle.graal.python.nodes.StringLiterals.J_NFI_LANGUAGE;
58+
59+
public class ArrowSupport {
60+
61+
protected final PythonContext ctx;
62+
63+
public ArrowSupport(PythonContext ctx) {
64+
this.ctx = ctx;
65+
}
5666

5767
// ArrowArray destructor
5868
private Object arrowArrayDestructorNFIClosure;
@@ -66,10 +76,6 @@ public class ArrowSupport extends AbstractArrowSupport {
6676
private Object arrowSchemaNFIClosure;
6777
@CompilationFinal private long arrowSchemaReleaseCallback;
6878

69-
public ArrowSupport(PythonContext ctx) {
70-
super(ctx);
71-
}
72-
7379
public long getArrowSchemaDestructor() {
7480
if (arrowSchemaDestructorCallback == 0) {
7581
CompilerDirectives.transferToInterpreterAndInvalidate();
@@ -97,7 +103,7 @@ public long getArrowSchemaReleaseCallback() {
97103
@TruffleBoundary
98104
private void initArrowArrayDestructor() {
99105
CompilerAsserts.neverPartOfCompilation();
100-
var signature = createNfiSignature("(POINTER):VOID");
106+
var signature = ArrowUtil.createNfiSignature("(POINTER):VOID", ctx);
101107
var executable = new ArrowArrayCapsuleDestructor();
102108
this.arrowArrayDestructorNFIClosure = SignatureLibrary.getUncached().createClosure(signature, executable);
103109
this.arrowArrayDestructor = PythonUtils.coerceToLong(arrowArrayDestructorNFIClosure, InteropLibrary.getUncached());
@@ -106,7 +112,7 @@ private void initArrowArrayDestructor() {
106112
@TruffleBoundary
107113
private void initArrowSchemaDestructor() {
108114
CompilerAsserts.neverPartOfCompilation();
109-
var signature = createNfiSignature("(POINTER):VOID");
115+
var signature = ArrowUtil.createNfiSignature("(POINTER):VOID", ctx);
110116
var executable = new ArrowSchemaCapsuleDestructor();
111117
this.arrowSchemaDestructorNFIClosure = SignatureLibrary.getUncached().createClosure(signature, executable);
112118
this.arrowSchemaDestructorCallback = PythonUtils.coerceToLong(arrowSchemaDestructorNFIClosure, InteropLibrary.getUncached());
@@ -115,7 +121,7 @@ private void initArrowSchemaDestructor() {
115121
@TruffleBoundary
116122
private void initArrowSchemaReleaseCallback() {
117123
CompilerAsserts.neverPartOfCompilation();
118-
var signature = createNfiSignature("(UINT64):VOID");
124+
var signature = ArrowUtil.createNfiSignature("(UINT64):VOID", ctx);
119125
var executable = new ArrowSchemaReleaseCallback();
120126
this.arrowSchemaNFIClosure = SignatureLibrary.getUncached().createClosure(signature, executable);
121127
this.arrowSchemaReleaseCallback = PythonUtils.coerceToLong(arrowSchemaNFIClosure, InteropLibrary.getUncached());

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/arrow/AbstractArrowSupport.java renamed to graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/arrow/ArrowUtil.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@
4545

4646
import static com.oracle.graal.python.nodes.StringLiterals.J_NFI_LANGUAGE;
4747

48-
public class AbstractArrowSupport {
48+
public class ArrowUtil {
4949

50-
protected final PythonContext ctx;
51-
52-
public AbstractArrowSupport(PythonContext ctx) {
53-
this.ctx = ctx;
54-
}
55-
56-
protected Object createNfiSignature(String methodSignature) {
50+
public static Object createNfiSignature(String methodSignature, PythonContext ctx) {
5751
Source sigSource = Source.newBuilder(J_NFI_LANGUAGE, methodSignature, "python-nfi-signature").build();
5852
return ctx.getEnv().parseInternal(sigSource).call();
5953
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/arrow/ArrowVectorSupport.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,19 @@
5050
import com.oracle.truffle.api.interop.InteropLibrary;
5151
import com.oracle.truffle.nfi.api.SignatureLibrary;
5252

53-
public class ArrowVectorSupport extends AbstractArrowSupport {
53+
public class ArrowVectorSupport {
5454

5555
private final String FIXED_WIDTH_VECTOR_PATH = "org.apache.arrow.vector.BaseFixedWidthVector";
5656

5757
public final boolean isJavaArrowImplOnClassPath;
5858
public final Class<?> baseFixedWidthVectorClass;
59+
private final PythonContext ctx;
5960

6061
private Object vectorArrowArrayNFIClosure;
6162
@CompilationFinal private long vectorArrowArrayReleaseCallback;
6263

6364
public ArrowVectorSupport(PythonContext ctx) {
64-
super(ctx);
65+
this.ctx = ctx;
6566
Class<?> baseFixedWidthVectorClass;
6667
try {
6768
baseFixedWidthVectorClass = Class.forName(FIXED_WIDTH_VECTOR_PATH);
@@ -88,7 +89,7 @@ public boolean isFixedWidthVector(Object vector) {
8889
@TruffleBoundary
8990
private void initVectorArrowArrayReleaseCallback() {
9091
CompilerAsserts.neverPartOfCompilation();
91-
var signature = createNfiSignature("(UINT64):VOID");
92+
var signature = ArrowUtil.createNfiSignature("(UINT64):VOID", ctx);
9293
var executable = new VectorArrowArrayReleaseCallback();
9394
this.vectorArrowArrayNFIClosure = SignatureLibrary.getUncached().createClosure(signature, executable);
9495
this.vectorArrowArrayReleaseCallback = PythonUtils.coerceToLong(vectorArrowArrayNFIClosure, InteropLibrary.getUncached());

graalpython/lib-graalpython/_polyglot.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ def _struct_time_tz(st: time.struct_time):
143143
is_time_zone=lambda t: t.tm_zone is not None or t.tm_gmtoff is not None,
144144
as_time_zone=_struct_time_tz)
145145

146+
# loading arrow structures on demand
147+
def __getattr__(name):
148+
if name == "arrow":
149+
from modules import _polyglot_arrow
150+
setattr(polyglot, "arrow", _polyglot_arrow)
151+
return _polyglot_arrow
152+
raise AttributeError(f"module 'polyglot' has no attribute '{name}'")
153+
154+
setattr(polyglot, "__getattr__", __getattr__)
155+
146156
# example extending time.struct_time using the decorator wrapper
147157
#
148158
# @polyglot.interop_behavior(time.struct_time)

graalpython/lib-graalpython/modules/interop/arrow.py renamed to graalpython/lib-graalpython/modules/_polyglot_arrow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import polyglot
4141
import java
4242

43-
4443
try:
4544
java.type("org.apache.arrow.vector.BaseFixedWidthVector")
4645
except KeyError:

graalpython/lib-graalpython/modules/interop/__init__.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)