-
Notifications
You must be signed in to change notification settings - Fork 335
Running Standard.Tableau in dual JVM mode #14607
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
2265316
7a03879
2bc5a6a
ee0b17b
2dc6895
2f37d20
d8730c9
9ab85b8
2d153e5
2592752
c888e18
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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| import java.io.FileOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.lang.reflect.Proxy; | ||
| import java.math.BigDecimal; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
|
|
@@ -54,6 +55,7 @@ | |
| import org.enso.table.data.table.Table; | ||
| import org.enso.table.problems.ProblemAggregator; | ||
| import org.graalvm.polyglot.Context; | ||
| import org.graalvm.polyglot.Value; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
@@ -168,7 +170,7 @@ public URL getResource(String name) { | |
| dotIdx == -1 ? name.substring(libIdx + 1) : name.substring(libIdx + 1, dotIdx); | ||
| // Windows libs don't have `lib` prefix. | ||
| var libName = osLibName.startsWith("lib") ? osLibName.substring(3) : osLibName; | ||
| var bindings = Context.getCurrent().getBindings("enso"); | ||
| var bindings = getBindings(); | ||
| var found = bindings.invokeMember("find_native_library", libName); | ||
| try { | ||
| if (found == null || found.asString() == null) { | ||
|
|
@@ -195,7 +197,7 @@ public InputStream getResourceAsStream(String name) { | |
| dotIdx == -1 ? name.substring(libIdx + 1) : name.substring(libIdx + 1, dotIdx); | ||
| // Windows libs don't have `lib` prefix. | ||
| var libName = osLibName.startsWith("lib") ? osLibName.substring(3) : osLibName; | ||
| var bindings = Context.getCurrent().getBindings("enso"); | ||
| var bindings = getBindings(); | ||
| var found = bindings.invokeMember("find_native_library", libName); | ||
| try { | ||
| if (found == null || found.asString() == null) { | ||
|
|
@@ -399,8 +401,18 @@ private static TableDefinition createTable( | |
| return tableDef; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static <T> StorageType<T> toLocal(StorageType<T> type) { | ||
| if (Proxy.isProxyClass(type.getClass())) { | ||
| var local = StorageType.fromTypeCharAndSize(type.typeChar(), type.size()); | ||
| return (StorageType<T>) local; | ||
| } else { | ||
| return type; | ||
| } | ||
| } | ||
|
|
||
| private static SqlType mapEnsoTypeToSqlType(StorageType<?> type) { | ||
| return switch (type) { | ||
| return switch (toLocal(type)) { | ||
| case TextType t -> SqlType.text(); | ||
| case IntegerType t -> SqlType.bigInt(); | ||
| case FloatType t -> SqlType.doublePrecision(); | ||
|
|
@@ -504,7 +516,39 @@ private static void addValueToInserter(Inserter inserter, ColumnStorage<?> stora | |
| case LocalTime lt -> inserter.add(lt); | ||
| case ZonedDateTime zdt -> inserter.add(zdt); | ||
| case BigDecimal bd -> inserter.add(bd); | ||
|
Member
Author
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. This code is different than the classical switch over |
||
| default -> throw new HyperUnsupportedTypeError(value.toString()); | ||
| default -> { | ||
| var v = Value.asValue(value); | ||
| if (v.isDate() && v.isTime() && v.isTimeZone()) { | ||
| inserter.add(ZonedDateTime.of(v.asDate(), v.asTime(), v.asTimeZone())); | ||
| } else if (v.isDate()) { | ||
| inserter.add(v.asDate()); | ||
| } else if (v.isTime()) { | ||
| inserter.add(v.asTime()); | ||
| } else if (v.fitsInLong()) { | ||
| inserter.add(v.asLong()); | ||
| } else if (v.fitsInDouble()) { | ||
| inserter.add(v.asDouble()); | ||
| } else if (v.isBoolean()) { | ||
| inserter.add(v.asBoolean()); | ||
| } else { | ||
| var type = value.getClass().getName(); | ||
| if (v.getMetaObject() instanceof Value meta) { | ||
| type = meta.getMetaQualifiedName(); | ||
| } | ||
| if ("java.math.BigDecimal".equals(type)) { | ||
|
Member
Author
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.
|
||
| var unscaledValue = v.invokeMember("unscaledValue"); | ||
| var scale = v.invokeMember("scale"); | ||
| if (unscaledValue != null | ||
| && unscaledValue.fitsInBigInteger() | ||
| && scale != null | ||
| && scale.fitsInInt()) { | ||
| inserter.add(new BigDecimal(unscaledValue.asBigInteger(), scale.asInt())); | ||
| return; | ||
| } | ||
| } | ||
| throw new HyperUnsupportedTypeError(value.toString() + " type: " + type); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -588,4 +632,14 @@ private static void validateTypesMatch(ColumnStorage<?>[] storages, TableDefinit | |
| } | ||
| } | ||
| } | ||
|
|
||
| private static Value getBindings() { | ||
| var ctx = Context.getCurrent(); | ||
| var bindings = ctx.getPolyglotBindings().getMember("ensoBindings"); | ||
| if (bindings != null) { | ||
| return bindings.execute("enso"); | ||
| } else { | ||
| return ctx.getBindings("enso"); | ||
| } | ||
| } | ||
| } | ||
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.