Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Big numbers support for standard deviation filter #306

Open
hacheigriega opened this issue Jul 22, 2024 · 0 comments
Open

✨ Big numbers support for standard deviation filter #306

hacheigriega opened this issue Jul 22, 2024 · 0 comments
Labels
type: feature ✨ New feature or request

Comments

@hacheigriega
Copy link
Member

hacheigriega commented Jul 22, 2024

✨ Feature

The following are the four number types and their corresponding number type bytecode supported by the standard deviation filter:

  • int32 (0x00)
  • int64 (0x01)
  • uint32 (0x02)
  • uint64 (0x03): Not fully supported because the ojg package converts large numbers to json.Number. which we do not deal with in the standard filter yet.

First, we need to add a full support for uint64 by parsing json.Number. We can make use of the generic type as follows:

		num, ok := data.(int64)
		if !ok {
			// Big numbers are stored as json.Number.
			bigNum, ok := data.(json.Number)
			if !ok {
				corruptQueue = append(corruptQueue, i)
				continue
			}

			var num T
			var err error
			rt := reflect.TypeOf(num)
			switch rt.Kind() {
			case reflect.Int32, reflect.Int64:
				var t int64
				t, err = strconv.ParseInt(bigNum.String(), 10, rt.Bits())
				num = T(t)
			case reflect.Uint32, reflect.Uint64:
				var t uint64
				t, err = strconv.ParseUint(bigNum.String(), 10, rt.Bits())
				num = T(t)
			default:
				return nil, ErrFilterUnexpected // should not be reachable
			}
			if err != nil {
				corruptQueue = append(corruptQueue, i)
				continue
			}
			nums = append(nums, T(num))
		}

Second, we need to clarify in the specifications the number ranges we support and possible overflow issues. We should perhaps add an overflow detection wherever it can happen such as when we cast number types or compute the median.

Third, we will add support for math/big numbers, which provide arbitrary-precision arithmetics.

@hacheigriega hacheigriega added the type: feature ✨ New feature or request label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant