MCPcopy Create free account
hub / github.com/apache/calcite / isLiteral

Method isLiteral

core/src/main/java/org/apache/calcite/sql/SqlUtil.java:245–266  ·  view source on GitHub ↗

Returns whether a node is a literal. Examples: For CAST(literal AS type ) , returns true if allowCast is true, false otherwise. For CAST(CAST(literal AS type ) AS type )) , returns false. @param node The node, never nul

(SqlNode node, boolean allowCast)

Source from the content-addressed store, hash-verified

243 * @return Whether the node is a literal
244 */
245 public static boolean isLiteral(SqlNode node, boolean allowCast) {
246 requireNonNull(node, "node");
247 if (node instanceof SqlLiteral) {
248 return true;
249 }
250 if (!allowCast) {
251 return false;
252 }
253 switch (node.getKind()) {
254 case CAST:
255 // "CAST(e AS type)" is literal if "e" is literal
256 return isLiteral(((SqlCall) node).operand(0), true);
257 case MAP_VALUE_CONSTRUCTOR:
258 case ARRAY_VALUE_CONSTRUCTOR:
259 return ((SqlCall) node).getOperandList().stream()
260 .allMatch(o -> isLiteral(o, true));
261 case DEFAULT:
262 return true; // DEFAULT is always NULL
263 default:
264 return false;
265 }
266 }
267
268 /**
269 * Returns whether a node is a literal.

Callers 4

testSqlNodeLiteralMethod · 0.95
getOptionAsStringMethod · 0.95
isOperandLiteralMethod · 0.95

Calls 5

operandMethod · 0.65
allMatchMethod · 0.65
streamMethod · 0.65
getKindMethod · 0.45
getOperandListMethod · 0.45

Tested by 1

testSqlNodeLiteralMethod · 0.76