From 2fb7fa67a117e46c7edc861a7c95b08c38c0306e Mon Sep 17 00:00:00 2001 From: Nate Bauernfeind Date: Wed, 10 Jan 2024 09:23:56 -0700 Subject: [PATCH 1/2] Log User-Friendly Error When AutoComplete is not Available (#4316) --- .../server/console/ConsoleServiceGrpcImpl.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/io/deephaven/server/console/ConsoleServiceGrpcImpl.java b/server/src/main/java/io/deephaven/server/console/ConsoleServiceGrpcImpl.java index 3fec26cab7b..864d1c1ad51 100644 --- a/server/src/main/java/io/deephaven/server/console/ConsoleServiceGrpcImpl.java +++ b/server/src/main/java/io/deephaven/server/console/ConsoleServiceGrpcImpl.java @@ -7,6 +7,7 @@ import com.google.rpc.Code; import io.deephaven.base.LockFreeArrayQueue; import io.deephaven.configuration.Configuration; +import io.deephaven.engine.context.QueryScope; import io.deephaven.engine.table.Table; import io.deephaven.engine.table.impl.perf.QueryPerformanceNugget; import io.deephaven.engine.table.impl.perf.QueryPerformanceRecorder; @@ -61,8 +62,10 @@ public class ConsoleServiceGrpcImpl extends ConsoleServiceGrpc.ConsoleServiceImp public static final boolean REMOTE_CONSOLE_DISABLED = Configuration.getInstance().getBooleanWithDefault("deephaven.console.disable", false); + private static final String DISABLE_AUTOCOMPLETE_FLAG = "deephaven.console.autocomplete.disable"; public static final boolean AUTOCOMPLETE_DISABLED = - Configuration.getInstance().getBooleanWithDefault("deephaven.console.autocomplete.disable", false); + Configuration.getInstance().getBooleanWithDefault(DISABLE_AUTOCOMPLETE_FLAG, false); + public static final boolean QUIET_AUTOCOMPLETE_ERRORS = Configuration.getInstance().getBooleanWithDefault("deephaven.console.autocomplete.quiet", true); @@ -75,6 +78,8 @@ public class ConsoleServiceGrpcImpl extends ConsoleServiceGrpc.ConsoleServiceImp public static final int SUBSCRIBE_TO_LOGS_BUFFER_SIZE = Configuration.getInstance().getIntegerWithDefault(SUBSCRIBE_TO_LOGS_BUFFER_SIZE_PROP, 32768); + private static final AtomicBoolean ALREADY_WARNED_ABOUT_NO_AUTOCOMPLETE = new AtomicBoolean(); + private final TicketRouter ticketRouter; private final SessionService sessionService; private final Provider scriptSessionProvider; @@ -296,7 +301,7 @@ public void bindTableToVariable( public StreamObserver autoCompleteStream( @NotNull final StreamObserver responseObserver) { final SessionState session = sessionService.getCurrentSession(); - if (AUTOCOMPLETE_DISABLED) { + if (AUTOCOMPLETE_DISABLED || ALREADY_WARNED_ABOUT_NO_AUTOCOMPLETE.get()) { return new NoopAutoCompleteObserver(session, responseObserver); } if (PythonDeephavenSession.SCRIPT_TYPE.equals(scriptSessionProvider.get().scriptType())) { @@ -307,7 +312,13 @@ public StreamObserver autoCompleteStream( "from deephaven_internal.auto_completer import jedi_settings ; jedi_settings.set_scope(globals())"); settings[0] = (PyObject) scriptSession.getVariable("jedi_settings"); } catch (Exception err) { - log.error().append("Error trying to enable jedi autocomplete").append(err).endl(); + if (!ALREADY_WARNED_ABOUT_NO_AUTOCOMPLETE.getAndSet(true)) { + log.error().append("Autocomplete package not found; disabling autocomplete.").endl(); + log.error().append("Do you need to install the autocomplete package?").endl(); + log.error().append(" pip install deephaven-core[autocomplete]==").endl(); + log.error().append("Add the jvm flag '-D").append(DISABLE_AUTOCOMPLETE_FLAG) + .append("=true' to disable this message.").endl(); + } } boolean canJedi = settings[0] != null && settings[0].call("can_jedi").getBooleanValue(); log.info().append(canJedi ? "Using jedi for python autocomplete" From da5a5dc8f4654e667b8de450f05af3701933d328 Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:32:30 -0700 Subject: [PATCH 2/2] Fix broken calendar unit tests over midnight. (#5025) * Fix broken calendar unit tests that run over midnight. Resolves #5024. --- .../java/io/deephaven/time/DateTimeUtils.java | 13 ++++++++---- .../time/calendar/TestBusinessCalendar.java | 20 +++++++++++-------- .../deephaven/time/calendar/TestCalendar.java | 10 +++++----- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/engine/time/src/main/java/io/deephaven/time/DateTimeUtils.java b/engine/time/src/main/java/io/deephaven/time/DateTimeUtils.java index 36a38b76428..12a5985a618 100644 --- a/engine/time/src/main/java/io/deephaven/time/DateTimeUtils.java +++ b/engine/time/src/main/java/io/deephaven/time/DateTimeUtils.java @@ -433,8 +433,7 @@ private CachedCurrentDate(@NotNull final ZoneId timeZone) { synchronized void update(final long currentTimeMillis) { date = toLocalDate(epochMillisToInstant(currentTimeMillis), timeZone); str = formatDate(date); - valueExpirationTimeMillis = - epochMillis(atMidnight(epochMillisToZonedDateTime(currentTimeMillis, timeZone)).plusDays(1)); + valueExpirationTimeMillis = epochMillis(date.plusDays(1).atStartOfDay(timeZone)); } } @@ -450,6 +449,10 @@ public ZoneId getKey(final CACHED_DATE_TYPE cachedDate) { private static final KeyedObjectHashMap cachedCurrentDates = new KeyedObjectHashMap<>(new CachedDateKey<>()); + private static CachedCurrentDate getCachedCurrentDate(@NotNull final ZoneId timeZone) { + return cachedCurrentDates.putIfAbsent(timeZone, CachedCurrentDate::new); + } + /** * Provides the current date string according to the {@link #currentClock() current clock}. Under most * circumstances, this method will return the date according to current system time, but during replay simulations, @@ -468,7 +471,7 @@ public static String today(@Nullable final ZoneId timeZone) { return null; } - return cachedCurrentDates.putIfAbsent(timeZone, CachedCurrentDate::new).getStr(); + return getCachedCurrentDate(timeZone).getStr(); } /** @@ -485,6 +488,7 @@ public static String today(@Nullable final ZoneId timeZone) { @ScriptApi @NotNull public static String today() { + // noinspection ConstantConditions return today(DateTimeUtils.timeZone()); } @@ -506,7 +510,7 @@ public static LocalDate todayLocalDate(@Nullable final ZoneId timeZone) { return null; } - return cachedCurrentDates.putIfAbsent(timeZone, CachedCurrentDate::new).getLocalDate(); + return getCachedCurrentDate(timeZone).getLocalDate(); } /** @@ -523,6 +527,7 @@ public static LocalDate todayLocalDate(@Nullable final ZoneId timeZone) { @ScriptApi @NotNull public static LocalDate todayLocalDate() { + // noinspection ConstantConditions return todayLocalDate(DateTimeUtils.timeZone()); } diff --git a/engine/time/src/test/java/io/deephaven/time/calendar/TestBusinessCalendar.java b/engine/time/src/test/java/io/deephaven/time/calendar/TestBusinessCalendar.java index 1e7596f625b..7fd3041cfa9 100644 --- a/engine/time/src/test/java/io/deephaven/time/calendar/TestBusinessCalendar.java +++ b/engine/time/src/test/java/io/deephaven/time/calendar/TestBusinessCalendar.java @@ -1503,29 +1503,33 @@ public void testMinusNonBusinessDays() { } public void testFutureBusinessDate() { - assertEquals(bCalendar.plusBusinessDays(DateTimeUtils.todayLocalDate(), 3), bCalendar.futureBusinessDate(3)); - assertEquals(bCalendar.plusBusinessDays(DateTimeUtils.todayLocalDate(), -3), bCalendar.futureBusinessDate(-3)); + assertEquals(bCalendar.plusBusinessDays(bCalendar.calendarDate(), 3), + bCalendar.futureBusinessDate(3)); + assertEquals(bCalendar.plusBusinessDays(bCalendar.calendarDate(), -3), + bCalendar.futureBusinessDate(-3)); assertNull(bCalendar.futureBusinessDate(NULL_INT)); } public void testPastBusinessDate() { - assertEquals(bCalendar.minusBusinessDays(DateTimeUtils.todayLocalDate(), 3), bCalendar.pastBusinessDate(3)); - assertEquals(bCalendar.minusBusinessDays(DateTimeUtils.todayLocalDate(), -3), bCalendar.pastBusinessDate(-3)); + assertEquals(bCalendar.minusBusinessDays(bCalendar.calendarDate(), 3), + bCalendar.pastBusinessDate(3)); + assertEquals(bCalendar.minusBusinessDays(bCalendar.calendarDate(), -3), + bCalendar.pastBusinessDate(-3)); assertNull(bCalendar.pastBusinessDate(NULL_INT)); } public void testFutureNonBusinessDate() { - assertEquals(bCalendar.plusNonBusinessDays(DateTimeUtils.todayLocalDate(), 3), + assertEquals(bCalendar.plusNonBusinessDays(bCalendar.calendarDate(), 3), bCalendar.futureNonBusinessDate(3)); - assertEquals(bCalendar.plusNonBusinessDays(DateTimeUtils.todayLocalDate(), -3), + assertEquals(bCalendar.plusNonBusinessDays(bCalendar.calendarDate(), -3), bCalendar.futureNonBusinessDate(-3)); assertNull(bCalendar.futureNonBusinessDate(NULL_INT)); } public void testPastNonBusinessDate() { - assertEquals(bCalendar.minusNonBusinessDays(DateTimeUtils.todayLocalDate(), 3), + assertEquals(bCalendar.minusNonBusinessDays(bCalendar.calendarDate(), 3), bCalendar.pastNonBusinessDate(3)); - assertEquals(bCalendar.minusNonBusinessDays(DateTimeUtils.todayLocalDate(), -3), + assertEquals(bCalendar.minusNonBusinessDays(bCalendar.calendarDate(), -3), bCalendar.pastNonBusinessDate(-3)); assertNull(bCalendar.pastNonBusinessDate(NULL_INT)); } diff --git a/engine/time/src/test/java/io/deephaven/time/calendar/TestCalendar.java b/engine/time/src/test/java/io/deephaven/time/calendar/TestCalendar.java index 8f8304ef0f1..4fbf1c76ee4 100644 --- a/engine/time/src/test/java/io/deephaven/time/calendar/TestCalendar.java +++ b/engine/time/src/test/java/io/deephaven/time/calendar/TestCalendar.java @@ -159,18 +159,18 @@ public void testMinusDays() { } public void testCurrentDate() { - assertEquals(DateTimeUtils.todayLocalDate(), calendar.calendarDate()); + assertEquals(calendar.calendarDate(), calendar.calendarDate()); } public void testFutureDate() { - assertEquals(calendar.plusDays(DateTimeUtils.todayLocalDate(), 3), calendar.futureDate(3)); - assertEquals(calendar.plusDays(DateTimeUtils.todayLocalDate(), -3), calendar.futureDate(-3)); + assertEquals(calendar.plusDays(calendar.calendarDate(), 3), calendar.futureDate(3)); + assertEquals(calendar.plusDays(calendar.calendarDate(), -3), calendar.futureDate(-3)); assertNull(calendar.futureDate(NULL_INT)); } public void testPastDate() { - assertEquals(calendar.minusDays(DateTimeUtils.todayLocalDate(), 3), calendar.pastDate(3)); - assertEquals(calendar.minusDays(DateTimeUtils.todayLocalDate(), -3), calendar.pastDate(-3)); + assertEquals(calendar.minusDays(calendar.calendarDate(), 3), calendar.pastDate(3)); + assertEquals(calendar.minusDays(calendar.calendarDate(), -3), calendar.pastDate(-3)); assertNull(calendar.pastDate(NULL_INT)); }