Code Monkey home page Code Monkey logo

Comments (3)

co63oc avatar co63oc commented on May 15, 2024

mysqld测试结果
mysql> SELECT JSON_OBJECT('id', 123, 'name', 'polardb-x');
+---------------------------------------------+
| JSON_OBJECT('id', 123, 'name', 'polardb-x') |
+---------------------------------------------+
| {"id": 123, "name": "polardb-x"} |
+---------------------------------------------+
1 row in set (0.00 sec)

from polardbx-sql.

co63oc avatar co63oc commented on May 15, 2024

polardbx-optimizer\src\main\java\com\alibaba\polardbx\optimizer\core\function\calc\scalar\json\JsonObject.java
对应源码,生fastjson成json时会有顺序,没找到怎么改变设置顺序

    @Override
    public Object compute(Object[] args, ExecutionContext ec) {
        if (args.length % 2 != 0) {
            throw JsonParserException.wrongParamCount(getFunctionNames()[0]);
        }

        Map<String, Object> resultJson = Maps.newHashMap();
        for (int i = 0; i < args.length; i += 2) {
            if (args[i] == null) {
                throw new JsonParserException("JSON documents may not contain NULL member names.");
            }

            if (i + 1 < args.length) {
                resultJson.put(DataTypeUtil.convert(operandTypes.get(i), DataTypes.StringType, args[i]), args[i + 1]);
            } else {
                throw JsonParserException.wrongParamCount(getFunctionNames()[0]);
            }
        }

        return JSON.toJSONString(resultJson);
    }

from polardbx-sql.

F-ca7 avatar F-ca7 commented on May 15, 2024

关于MySQL 对 json_object输出顺序的描述:https://dev.mysql.com/doc/refman/8.0/en/json.html#json-normalization

To make lookups more efficient, MySQL also sorts the keys of a JSON object. You should be aware that the result of this ordering is subject to change and not guaranteed to be consistent across releases.

MySQL会对 JSON对象的key进行排序,但是不保证这个顺序在每个发行版都是一致的。

而PolarDB-X中调用了FastJson的接口,底层com.alibaba.fastjson.serializer.MapSerializer 是基于HashMap的遍历,这个同样也是不保证顺序的。

from polardbx-sql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.