code: private void handleScalarSubQuery(
  		SqlSelect parentSelect,
  		SqlSelect selectItem,
  		List<SqlNode> expandedSelectItems,
  		Set<String> aliasList,
  		List<Map.Entry<String, RelDataType>> fieldList) {
  		// A scalar sub-query only has one output column.
  		if (1 != selectItem.getSelectList().size()) {
  			throw newValidationError(selectItem,
  				RESOURCE.onlyScalarSubQueryAllowed());
  		}
  
  		// No expansion in this routine just append to list.
  		expandedSelectItems.add(selectItem);
  
  		// Get or generate alias and add to list.
  		final String alias =
  			deriveAlias(
  				selectItem,
  				aliasList.size());
  		aliasList.add(alias);
  
  		final SelectScope scope = (SelectScope) getWhereScope(parentSelect);
  		final RelDataType type = deriveType(scope, selectItem);
  		setValidatedNodeType(selectItem, type);
  
  		// we do not want to pass on the RelRecordType returned
  		// by the sub query.  Just the type of the single expression
  		// in the sub-query select list.
  		assert type instanceof RelRecordType;
  		RelRecordType rec = (RelRecordType) type;
  
  		RelDataType nodeType = rec.getFieldList().get(0).getType();
  		nodeType = typeFactory.createTypeWithNullability(nodeType, true);
  		fieldList.add(Pair.of(alias, nodeType));
  	}
docs: Processes SubQuery found in Select list. Checks that is actually Scalar
  sub-query and makes proper entries in each of the 3 lists used to create
  the final rowType entry.
  
  @param parentSelect        base SqlSelect item
  @param selectItem          child SqlSelect from select list
  @param expandedSelectItems Select items after processing
  @param aliasList           built from user or system values
  @param fieldList           Built up entries for each select list entry