Source:
<code>private static Optional<Subfield> toSubfield( RowExpression expression, StandardFunctionResolution functionResolution, ExpressionOptimizer expressionOptimizer, ConnectorSession connectorSession) { ImmutableList.Builder<Subfield.PathElement> elements = ImmutableList.builder(); while (true) { if (expression instanceof VariableReferenceExpression) { return Optional.of(new Subfield(((VariableReferenceExpression) expression).getName(), elements.build().reverse())); } if (expression instanceof SpecialFormExpression && ((SpecialFormExpression) expression).getForm() == DEREFERENCE) { SpecialFormExpression dereference = (SpecialFormExpression) expression; RowExpression base = dereference.getArguments().get(0); RowType baseType = (RowType) base.getType(); RowExpression indexExpression = expressionOptimizer.optimize( dereference.getArguments().get(1), ExpressionOptimizer.Level.OPTIMIZED, connectorSession); if (indexExpression instanceof ConstantExpression) { Object index = ((ConstantExpression) indexExpression).getValue(); if (index instanceof Number) { Optional<String> fieldName = baseType.getFields().get(((Number) index).intValue()).getName(); if (fieldName.isPresent()) { elements.add(nestedField(fieldName.get())); expression = base; continue; } } } return Optional.empty(); } if (expression instanceof CallExpression && functionResolution.isSubscriptFunction(((CallExpression) expression).getFunctionHandle())) { List<RowExpression> arguments = ((CallExpression) expression).getArguments(); RowExpression indexExpression = expressionOptimizer.optimize( arguments.get(1), ExpressionOptimizer.Level.OPTIMIZED, connectorSession); if (indexExpression instanceof ConstantExpression) { Object index = ((ConstantExpression) indexExpression).getValue(); if (index == null) { <START> return Optional.empty(); <END> } if (index instanceof Number) { elements.add(new Subfield.LongSubscript(((Number) index).longValue())); expression = arguments.get(0); continue; } if (isVarcharType(indexExpression.getType())) { elements.add(new Subfield.StringSubscript(((Slice) index).toStringUtf8())); expression = arguments.get(0); continue; } } return Optional.empty(); } return Optional.empty(); } }</code><technical_language>Do need check L501</technical_language>

Target:
private static Optional<Subfield> toSubfield( RowExpression expression, StandardFunctionResolution functionResolution, ExpressionOptimizer expressionOptimizer, ConnectorSession connectorSession) { ImmutableList.Builder<Subfield.PathElement> elements = ImmutableList.builder(); while (true) { if (expression instanceof VariableReferenceExpression) { return Optional.of(new Subfield(((VariableReferenceExpression) expression).getName(), elements.build().reverse())); } if (expression instanceof SpecialFormExpression && ((SpecialFormExpression) expression).getForm() == DEREFERENCE) { SpecialFormExpression dereference = (SpecialFormExpression) expression; RowExpression base = dereference.getArguments().get(0); RowType baseType = (RowType) base.getType(); RowExpression indexExpression = expressionOptimizer.optimize( dereference.getArguments().get(1), ExpressionOptimizer.Level.OPTIMIZED, connectorSession); if (indexExpression instanceof ConstantExpression) { Object index = ((ConstantExpression) indexExpression).getValue(); verify(index != null, "Struct field index cannot be null"); if (index instanceof Number) { Optional<String> fieldName = baseType.getFields().get(((Number) index).intValue()).getName(); if (fieldName.isPresent()) { elements.add(nestedField(fieldName.get())); expression = base; continue; } } } return Optional.empty(); } if (expression instanceof CallExpression && functionResolution.isSubscriptFunction(((CallExpression) expression).getFunctionHandle())) { List<RowExpression> arguments = ((CallExpression) expression).getArguments(); RowExpression indexExpression = expressionOptimizer.optimize( arguments.get(1), ExpressionOptimizer.Level.OPTIMIZED, connectorSession); if (indexExpression instanceof ConstantExpression) { Object index = ((ConstantExpression) indexExpression).getValue(); if (index == null) { return Optional.empty(); } if (index instanceof Number) { elements.add(new Subfield.LongSubscript(((Number) index).longValue())); expression = arguments.get(0); continue; } if (isVarcharType(indexExpression.getType())) { elements.add(new Subfield.StringSubscript(((Slice) index).toStringUtf8())); expression = arguments.get(0); continue; } } return Optional.empty(); } return Optional.empty(); } }