@@ -76,6 +76,7 @@ def parser():
76
76
MIN_OP : str = "min"
77
77
MINUS_OP : str = "minus" # (column1 - column2) or (column - value)
78
78
MOD_OP : str = "mod" # (column mod column) or (column mod value)
79
+ MULTIPLY_OP : str = "multiply" # (column x column) or (column x value)
79
80
NEGATE_OP : str = "negate" # (column, ...)
80
81
NUMBER_OP : str = "number" # Get a number or the numeric part of a quantity.
81
82
PERCENTAGE_OP : str = "percentage"
@@ -1855,6 +1856,27 @@ def mod_op()->bool:
1855
1856
return True
1856
1857
opfunc = mod_op
1857
1858
1859
+ elif operation == MULTIPLY_OP :
1860
+ if not ((len (sources ) == 2 and len (values ) == 0 ) or (len (sources ) == 1 and len (values ) == 1 )):
1861
+ raise KGTKException ("Multiply needs two sources or one source and one value, got %d sources and %d values" % (len (sources ), len (values )))
1862
+ if len (into_column_idxs ) != 1 :
1863
+ raise KGTKException ("Multiply needs 1 destination columns, got %d" % len (into_column_idxs ))
1864
+
1865
+ def multiply_2_op ()-> bool :
1866
+ # TODO: support quantities.
1867
+ output_row [into_column_idx ] = str (float (row [sources [0 ]]) * float (row [sources [1 ]]))
1868
+ return True
1869
+
1870
+ def multiply_1op ()-> bool :
1871
+ # TODO: support quantities.
1872
+ output_row [into_column_idx ] = str (float (row [sources [0 ]]) * float (values [0 ]))
1873
+ return True
1874
+
1875
+ if len (sources ) == 2 :
1876
+ opfunc = multiply_2_op
1877
+ else :
1878
+ opfunc = multiply_1_op
1879
+
1858
1880
elif operation == NAND_OP :
1859
1881
if len (sources ) == 0 :
1860
1882
raise KGTKException ("Nand needs at least one source, got %d" % len (sources ))
0 commit comments