public FeatureResult getOnlineFeatures()

in src/main/java/com/aliyun/openservices/paifeaturestore/domain/FeatureView.java [238:295]


    public FeatureResult getOnlineFeatures(String[] joinIds, String[] features, Map<String, String> aliasFields) throws Exception {
        List<String> selectFields = new ArrayList<>();
        selectFields.add(this.primaryKeyField.getName());
        for (String featureName : features) {
            if ("*".equals(featureName)) {
                selectFields.addAll(this.featureFields);
            } else {
                if (!this.featureFields.contains(featureName)) {
                    throw new RuntimeException(String.format("feature name :%s not found in the featureview fields", featureName));
                }

                selectFields.add(featureName);
            }
        }

        if (null != aliasFields) {
            for (String featureName : aliasFields.keySet()) {
                if (!this.featureFields.contains(featureName)) {
                    throw new RuntimeException(String.format("alias fields feature name :%s not found in the featureview fields", featureName));
                }
            }
        }

        FeatureStoreResult featureStoreResult = (FeatureStoreResult) this.featureViewDao.getFeatures(joinIds, selectFields.toArray(new String[0]));

        String[] featureFields = featureStoreResult.getFeatureFields();
        List<String> featureFieldList = new ArrayList<>(Arrays.asList(featureFields));
        Map<String, FSType> fieldTypeMap = featureStoreResult.getFeatureFieldTypeMap();

        if (!this.primaryKeyField.getName().equals(this.featureEntity.getFeatureEntity().getFeatureEntityJoinid())) {
            for (Map<String, Object> featureMap : featureStoreResult.getFeatureData()) {
                featureMap.put(this.featureEntity.getFeatureEntity().getFeatureEntityJoinid(), featureMap.get(this.primaryKeyField.getName()));
                featureMap.remove(this.primaryKeyField.getName());
                featureFieldList.add(this.featureEntity.getFeatureEntity().getFeatureEntityJoinid());
                featureFieldList.remove(this.primaryKeyField.getName());

                fieldTypeMap.put(this.featureEntity.getFeatureEntity().getFeatureEntityJoinid(), fieldTypeMap.get(this.primaryKeyField.getName()));
            }
        }

        if (null != aliasFields) {
            for (Map.Entry<String, String> entry : aliasFields.entrySet()) {
                for (Map<String, Object> featureMap : featureStoreResult.getFeatureData()) {
                    if (featureMap.containsKey(entry.getKey())) {
                        featureMap.put(entry.getValue(), featureMap.get(entry.getKey()));
                        featureMap.remove(entry.getKey());
                    }
                }
                featureFieldList.add(entry.getValue());
                featureFieldList.remove(entry.getKey());
                fieldTypeMap.put(entry.getValue(), fieldTypeMap.get(entry.getKey()));
            }
        }

        featureStoreResult.setFeatureFields(featureFieldList.toArray(new String[0]));

        return featureStoreResult;
    }