This is an automated email from the ASF dual-hosted git repository.

mboehm7 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 16094701f4 [SYSTEMDS-3838] Fix unsupported expressions of boolean 
literals
16094701f4 is described below

commit 16094701f46b2299dd011c5dc62a48d8648865e1
Author: Matthias Boehm <[email protected]>
AuthorDate: Thu Feb 13 17:27:21 2025 +0100

    [SYSTEMDS-3838] Fix unsupported expressions of boolean literals
    
    This patch removes an unnecessary parser error when encountering
    binary expressions of boolean literals. Internally we anyway handle
    such expressions (which often occur after constant propagation).
---
 .../org/apache/sysds/parser/DMLTranslator.java     | 10 ++--
 .../test/functions/misc/BooleanExpressionTest.java | 59 ++++++++++++++++++++++
 src/test/scripts/functions/misc/booleanExpr.dml    | 23 +++++++++
 3 files changed, 86 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/sysds/parser/DMLTranslator.java 
b/src/main/java/org/apache/sysds/parser/DMLTranslator.java
index 2b4131d0ad..cd58af6233 100644
--- a/src/main/java/org/apache/sysds/parser/DMLTranslator.java
+++ b/src/main/java/org/apache/sysds/parser/DMLTranslator.java
@@ -1835,14 +1835,12 @@ public class DMLTranslator
                        constRight = (source.getRight().getOutput() instanceof 
ConstIdentifier);
                }
 
-               if (constLeft || constRight) {
-                       throw new RuntimeException(source.printErrorLocation() 
+ "Boolean expression with constant unsupported");
-               }
-
-               Hop left = processExpression(source.getLeft(), null, hops);
+               Hop left = !constLeft ? processExpression(source.getLeft(), 
null, hops) : 
+                       new 
LiteralOp(Boolean.valueOf(source.getLeft().getText().toLowerCase()));
                Hop right = null;
                if (source.getRight() != null) {
-                       right = processExpression(source.getRight(), null, 
hops);
+                       right = !constRight ? 
processExpression(source.getRight(), null, hops) :
+                               new 
LiteralOp(Boolean.valueOf(source.getRight().getText().toLowerCase()));
                }
 
                //prepare target identifier and ensure that output type is 
boolean 
diff --git 
a/src/test/java/org/apache/sysds/test/functions/misc/BooleanExpressionTest.java 
b/src/test/java/org/apache/sysds/test/functions/misc/BooleanExpressionTest.java
new file mode 100644
index 0000000000..178135c339
--- /dev/null
+++ 
b/src/test/java/org/apache/sysds/test/functions/misc/BooleanExpressionTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.sysds.test.functions.misc;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.junit.Test;
+
+public class BooleanExpressionTest extends AutomatedTestBase {
+       private final static String TEST_NAME1 = "booleanExpr";
+       private final static String TEST_DIR = "functions/misc/";
+       private final static String TEST_CLASS_DIR = TEST_DIR + 
BooleanExpressionTest.class.getSimpleName() + "/";
+
+       @Override
+       public void setUp() {
+               TestUtils.clearAssertionInformation();
+               addTestConfiguration(TEST_NAME1, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] {}));
+       }
+
+       @Test
+       public void testPrintNotExpressionTest() {
+               TestConfiguration config = getTestConfiguration(TEST_NAME1);
+               loadTestConfiguration(config);
+               String HOME = SCRIPT_DIR + TEST_DIR;
+               fullDMLScriptName = HOME + TEST_NAME1 + ".dml";
+               try{
+                       programArgs = new String[]{};
+                       setOutputBuffering(true);
+                       String out = runTest(null).toString();
+                       assertTrue(out.contains("FALSE\nTRUE")
+                                       || out.contains("FALSE\r\nTRUE"));
+               }
+               catch(Exception e){
+                       e.printStackTrace();
+                       fail();
+               }
+       }
+}
diff --git a/src/test/scripts/functions/misc/booleanExpr.dml 
b/src/test/scripts/functions/misc/booleanExpr.dml
new file mode 100644
index 0000000000..d273694a87
--- /dev/null
+++ b/src/test/scripts/functions/misc/booleanExpr.dml
@@ -0,0 +1,23 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+print(TRUE & FALSE);
+print(TRUE & !FALSE);

Reply via email to