Skip to content

Commit b6190db

Browse files
Don't use --enable-preview option needlessly (#13204)
The usage of `--enable-preview` is causing problems when switching between frgaal and javac. JDK's compiler only allows `--enable-preview` with the latest `--target` e.g. `24`. This affects also other JDK utilities like `javadoc`. As a result I was unable to use `persistance/doc` to generate Javadoc when working on #13201. The only reason why we are using`--enable-preview` is **usage of `_` in `switch` statements**. It is not really convincing reason for requiring preview mode. Hence this PR removes `--enable-preview` setting from `build.sbt` and changes the affected code to give the variable another name than `_`. # Important Notes The best solution would be for frgaal to `--enable-preview` by default (at the end the language is controlled by version of the frgaal compiler, no need for another switch) or offer some other (JDK javac unknown) option `-Denable.preview=true` to enable preview or offer an option to _disable preview_. That way it would be easier to switch between frgaal and latest JDK's `javadoc` without changing the arguments for the compilation. That's however a discussion to be held elsewhere.
1 parent 7e0c637 commit b6190db

File tree

4 files changed

+90
-91
lines changed

4 files changed

+90
-91
lines changed

build.sbt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,7 +2734,7 @@ def customFrgaalJavaCompilerSettings(targetJdk: String) = {
27342734
frgaalSourceLevel
27352735
) ++
27362736
(if (Integer.parseInt(targetJdk) <= 21) {
2737-
Seq("--enable-preview")
2737+
Seq()
27382738
} else {
27392739
Seq("-target", "21")
27402740
})
@@ -2747,8 +2747,7 @@ lazy val instrumentationSettings =
27472747
commands += WithDebugCommand.withDebug,
27482748
Compile / javacOptions --= Seq(
27492749
"-source",
2750-
frgaalSourceLevel,
2751-
"--enable-preview"
2750+
frgaalSourceLevel
27522751
),
27532752
libraryDependencies ++= Seq(
27542753
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion % "provided",
@@ -3194,8 +3193,7 @@ lazy val `runtime-benchmarks` =
31943193
Some("org.enso.interpreter.bench.benchmarks.RuntimeBenchmarksRunner"),
31953194
javacOptions --= Seq(
31963195
"-source",
3197-
frgaalSourceLevel,
3198-
"--enable-preview"
3196+
frgaalSourceLevel
31993197
),
32003198
parallelExecution := false,
32013199
Compile / moduleDependencies ++= {

std-bits/table/src/main/java/org/enso/table/data/column/builder/BigIntegerBuilder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ public final class BigIntegerBuilder extends TypedBuilder<BigInteger> {
2525

2626
@Override
2727
public boolean canRetypeTo(StorageType<?> type) {
28-
return type instanceof FloatType
29-
|| type instanceof BigDecimalType;
28+
return type instanceof FloatType || type instanceof BigDecimalType;
3029
}
3130

3231
@Override
3332
public Builder retypeTo(StorageType<?> type) {
3433
switch (type) {
35-
case FloatType _ -> {
34+
case FloatType floatType -> {
3635
// Needs to be an InferredDoubleBuilder so we can keep the raw data.
3736
var res = new InferredDoubleBuilder(currentSize, problemAggregator);
3837
for (int i = 0; i < currentSize; i++) {
@@ -44,7 +43,7 @@ public Builder retypeTo(StorageType<?> type) {
4443
}
4544
return res;
4645
}
47-
case BigDecimalType _ -> {
46+
case BigDecimalType bigDecimalType -> {
4847
var res = Builder.getForBigDecimal(data.length);
4948
for (int i = 0; i < currentSize; i++) {
5049
if (data[i] == null) {

std-bits/table/src/main/java/org/enso/table/data/column/builder/Builder.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.enso.table.data.column.builder;
22

3+
import java.math.BigDecimal;
4+
import java.math.BigInteger;
5+
import java.time.LocalDate;
6+
import java.time.LocalTime;
7+
import java.time.ZonedDateTime;
38
import java.util.Objects;
49
import org.enso.table.data.column.storage.Storage;
510
import org.enso.table.data.column.storage.type.AnyObjectType;
@@ -17,19 +22,12 @@
1722
import org.enso.table.data.column.storage.type.TimeOfDayType;
1823
import org.enso.table.problems.ProblemAggregator;
1924

20-
import java.math.BigDecimal;
21-
import java.math.BigInteger;
22-
import java.time.LocalDate;
23-
import java.time.LocalTime;
24-
import java.time.ZonedDateTime;
25-
2625
/** Interface defining a builder for creating columns dynamically. */
2726
public interface Builder {
2827
/**
29-
* The maximum size of a builder.
30-
* Currently, just the maximum value of an integer, but should be tested and limited.
31-
* For array based builders, must be less than the maximum array size.
32-
* */
28+
* The maximum size of a builder. Currently, just the maximum value of an integer, but should be
29+
* tested and limited. For array based builders, must be less than the maximum array size.
30+
*/
3331
int MAX_SIZE = Integer.MAX_VALUE;
3432

3533
/** Checks that the size is within the maximum allowed. */
@@ -38,7 +36,7 @@ static int checkSize(long size) {
3836
throw new IllegalArgumentException("Columns cannot exceed " + MAX_SIZE + " rows.");
3937
}
4038

41-
return (int)size;
39+
return (int) size;
4240
}
4341

4442
/**
@@ -50,17 +48,17 @@ static int checkSize(long size) {
5048
static Builder getForType(StorageType<?> type, long size, ProblemAggregator problemAggregator) {
5149
Builder builder =
5250
switch (type) {
53-
case AnyObjectType _ -> getForAnyObject(size);
54-
case BooleanType _ -> getForBoolean(size);
55-
case DateType _ -> getForDate(size);
56-
case DateTimeType _ -> getForDateTime(size);
57-
case TimeOfDayType _ -> getForTime(size);
51+
case AnyObjectType t -> getForAnyObject(size);
52+
case BooleanType t -> getForBoolean(size);
53+
case DateType t -> getForDate(size);
54+
case DateTimeType t -> getForDateTime(size);
55+
case TimeOfDayType t -> getForTime(size);
5856
case FloatType floatType -> getForDouble(floatType, size, problemAggregator);
5957
case IntegerType integerType -> getForLong(integerType, size, problemAggregator);
6058
case TextType textType -> getForText(textType, size);
61-
case BigDecimalType _ -> getForBigDecimal(size);
62-
case BigIntegerType _ -> getForBigInteger(size, problemAggregator);
63-
case NullType x -> new NullBuilder();
59+
case BigDecimalType t -> getForBigDecimal(size);
60+
case BigIntegerType t -> getForBigInteger(size, problemAggregator);
61+
case NullType t -> new NullBuilder();
6462
case null -> getInferredBuilder(size, problemAggregator);
6563
};
6664

@@ -121,8 +119,7 @@ static BuilderForDouble getForDouble(
121119
}
122120

123121
/**
124-
* Constructs a builder for storing objects.
125-
* No operations will be supported on this builder.
122+
* Constructs a builder for storing objects. No operations will be supported on this builder.
126123
*
127124
* @param size the initial size of the builder.
128125
*/
@@ -141,7 +138,8 @@ static BuilderForType<BigDecimal> getForBigDecimal(long size) {
141138
return new BigDecimalBuilder(checkedSize);
142139
}
143140

144-
static BuilderForType<BigInteger> getForBigInteger(long size, ProblemAggregator problemAggregator) {
141+
static BuilderForType<BigInteger> getForBigInteger(
142+
long size, ProblemAggregator problemAggregator) {
145143
int checkedSize = checkSize(size);
146144
return new BigIntegerBuilder(checkedSize, problemAggregator);
147145
}

std-bits/tableau/src/main/java/org/enso/tableau/HyperFormat.java

Lines changed: 64 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.FileOutputStream;
88
import java.io.IOException;
99
import java.io.InputStream;
10+
import java.math.BigDecimal;
1011
import java.net.MalformedURLException;
1112
import java.net.URI;
1213
import java.net.URISyntaxException;
@@ -15,7 +16,6 @@
1516
import java.nio.file.Files;
1617
import java.nio.file.InvalidPathException;
1718
import java.nio.file.Path;
18-
import java.math.BigDecimal;
1919
import java.time.LocalDate;
2020
import java.time.LocalTime;
2121
import java.time.ZonedDateTime;
@@ -25,17 +25,16 @@
2525
import java.util.logging.Level;
2626
import java.util.logging.Logger;
2727
import java.util.stream.IntStream;
28-
2928
import org.enso.table.data.column.storage.ColumnBooleanStorage;
3029
import org.enso.table.data.column.storage.ColumnDoubleStorage;
3130
import org.enso.table.data.column.storage.ColumnLongStorage;
3231
import org.enso.table.data.column.storage.type.BigDecimalType;
33-
import org.enso.table.data.column.storage.type.IntegerType;
34-
import org.enso.table.data.column.storage.type.TextType;
35-
import org.enso.table.data.column.storage.type.FloatType;
3632
import org.enso.table.data.column.storage.type.BooleanType;
3733
import org.enso.table.data.column.storage.type.DateTimeType;
3834
import org.enso.table.data.column.storage.type.DateType;
35+
import org.enso.table.data.column.storage.type.FloatType;
36+
import org.enso.table.data.column.storage.type.IntegerType;
37+
import org.enso.table.data.column.storage.type.TextType;
3938
import org.enso.table.data.column.storage.type.TimeOfDayType;
4039
import org.enso.table.data.table.Column;
4140
import org.enso.table.data.table.Table;
@@ -331,74 +330,79 @@ public static Column[] readTable(
331330
}
332331
}
333332

334-
public static void writeTable(String path, String schemaName, String tableName, Table table) throws IOException {
333+
public static void writeTable(String path, String schemaName, String tableName, Table table)
334+
throws IOException {
335335
getProcess();
336-
try (var connection = new Connection(process.getEndpoint(), path, CreateMode.CREATE_IF_NOT_EXISTS)) {
336+
try (var connection =
337+
new Connection(process.getEndpoint(), path, CreateMode.CREATE_IF_NOT_EXISTS)) {
337338
var tableDef = createTable(schemaName, tableName, table.getColumns(), connection);
338339
insertData(table, tableDef, connection);
339340
}
340341
}
341342

342-
private static TableDefinition createTable(String schemaName, String tableName, Column[] columns, Connection connection) {
343-
final var sn = new SchemaName(schemaName);
344-
if (!connection.getCatalog().getSchemaNames().contains(sn)) {
345-
connection.getCatalog().createSchema(sn);
346-
}
347-
348-
var tableDef = new TableDefinition(new TableName(schemaName, tableName));
349-
for (var col : columns) {
350-
String columnName = col.getName();
351-
var storage = col.getStorage();
352-
switch (storage.getType()) {
353-
case TextType _ -> tableDef.addColumn(columnName, SqlType.text());
354-
case IntegerType _ -> tableDef.addColumn(columnName, SqlType.bigInt());
355-
case FloatType _ -> tableDef.addColumn(columnName, SqlType.doublePrecision());
356-
case BooleanType _ -> tableDef.addColumn(columnName, SqlType.bool());
357-
case DateType _ -> tableDef.addColumn(columnName, SqlType.date());
358-
case TimeOfDayType _ -> tableDef.addColumn(columnName, SqlType.time());
359-
case DateTimeType _ -> tableDef.addColumn(columnName, SqlType.timestampTz());
343+
private static TableDefinition createTable(
344+
String schemaName, String tableName, Column[] columns, Connection connection) {
345+
final var sn = new SchemaName(schemaName);
346+
if (!connection.getCatalog().getSchemaNames().contains(sn)) {
347+
connection.getCatalog().createSchema(sn);
348+
}
349+
350+
var tableDef = new TableDefinition(new TableName(schemaName, tableName));
351+
for (var col : columns) {
352+
String columnName = col.getName();
353+
var storage = col.getStorage();
354+
switch (storage.getType()) {
355+
case TextType t -> tableDef.addColumn(columnName, SqlType.text());
356+
case IntegerType t -> tableDef.addColumn(columnName, SqlType.bigInt());
357+
case FloatType t -> tableDef.addColumn(columnName, SqlType.doublePrecision());
358+
case BooleanType t -> tableDef.addColumn(columnName, SqlType.bool());
359+
case DateType t -> tableDef.addColumn(columnName, SqlType.date());
360+
case TimeOfDayType t -> tableDef.addColumn(columnName, SqlType.time());
361+
case DateTimeType t -> tableDef.addColumn(columnName, SqlType.timestampTz());
360362
// https://tableau.github.io/hyper-db/docs/sql/datatype/numeric
361-
// Precisions over 18 require 128-bit for internal storage. Processing 128-bit numeric values is
362-
// often slower than processing 64-bit values, so it is advisable to use a sensible precision for
363+
// Precisions over 18 require 128-bit for internal storage. Processing 128-bit numeric
364+
// values is
365+
// often slower than processing 64-bit values, so it is advisable to use a sensible
366+
// precision for
363367
// the use case at hand instead of always using the maximum precision by default.
364-
case BigDecimalType _ -> tableDef.addColumn(columnName, SqlType.numeric(18, 9));
365-
default -> throw new HyperUnsupportedTypeError(storage.getType().toString());
366-
}
368+
case BigDecimalType t -> tableDef.addColumn(columnName, SqlType.numeric(18, 9));
369+
default -> throw new HyperUnsupportedTypeError(storage.getType().toString());
367370
}
368-
connection.executeCommand("DROP TABLE IF EXISTS \""+schemaName+"\".\""+tableName+"\"");
369-
connection.getCatalog().createTable(tableDef);
370-
return tableDef;
371+
}
372+
connection.executeCommand("DROP TABLE IF EXISTS \"" + schemaName + "\".\"" + tableName + "\"");
373+
connection.getCatalog().createTable(tableDef);
374+
return tableDef;
371375
}
372376

373-
private static void insertData(Table table, TableDefinition tableDef, Connection connection){
374-
int numberOfRows = table.rowCount();
375-
int numberOfColumns = table.getColumns().length;
376-
Inserter inserter = new Inserter(connection, tableDef);
377-
for (int row = 0; row < numberOfRows; ++row) {
378-
for (int col = 0; col < numberOfColumns; ++col) {
379-
var storage = table.getColumns()[col].getStorage();
380-
if (storage.isNothing(row)) {
381-
inserter.addNull();
382-
} else if (storage instanceof ColumnDoubleStorage doubleStorage) {
383-
inserter.add(doubleStorage.getItemAsDouble(row));
384-
} else if (storage instanceof ColumnLongStorage longStorage) {
385-
inserter.add(longStorage.getItemAsLong(row));
386-
} else if (storage instanceof ColumnBooleanStorage boolStorage) {
387-
inserter.add(boolStorage.getItemAsBoolean(row));
388-
} else {
389-
Object value = storage.getItemBoxed(row);
390-
switch (value) {
391-
case String s -> inserter.add(s);
392-
case LocalDate ld -> inserter.add(ld);
393-
case LocalTime lt -> inserter.add(lt);
394-
case ZonedDateTime zdt -> inserter.add(zdt);
395-
case BigDecimal bd -> inserter.add(bd);
396-
default -> throw new HyperUnsupportedTypeError(value.toString());
397-
}
377+
private static void insertData(Table table, TableDefinition tableDef, Connection connection) {
378+
int numberOfRows = table.rowCount();
379+
int numberOfColumns = table.getColumns().length;
380+
Inserter inserter = new Inserter(connection, tableDef);
381+
for (int row = 0; row < numberOfRows; ++row) {
382+
for (int col = 0; col < numberOfColumns; ++col) {
383+
var storage = table.getColumns()[col].getStorage();
384+
if (storage.isNothing(row)) {
385+
inserter.addNull();
386+
} else if (storage instanceof ColumnDoubleStorage doubleStorage) {
387+
inserter.add(doubleStorage.getItemAsDouble(row));
388+
} else if (storage instanceof ColumnLongStorage longStorage) {
389+
inserter.add(longStorage.getItemAsLong(row));
390+
} else if (storage instanceof ColumnBooleanStorage boolStorage) {
391+
inserter.add(boolStorage.getItemAsBoolean(row));
392+
} else {
393+
Object value = storage.getItemBoxed(row);
394+
switch (value) {
395+
case String s -> inserter.add(s);
396+
case LocalDate ld -> inserter.add(ld);
397+
case LocalTime lt -> inserter.add(lt);
398+
case ZonedDateTime zdt -> inserter.add(zdt);
399+
case BigDecimal bd -> inserter.add(bd);
400+
default -> throw new HyperUnsupportedTypeError(value.toString());
398401
}
399402
}
400-
inserter.endRow();
401403
}
402-
inserter.execute();
404+
inserter.endRow();
405+
}
406+
inserter.execute();
403407
}
404408
}

0 commit comments

Comments
 (0)