| 188 | } |
| 189 | |
| 190 | SvecType * svec_in_internal(char * str) |
| 191 | { |
| 192 | char *values; |
| 193 | ArrayType *pgarray_vals,*pgarray_ix; |
| 194 | double *vals, *vals_temp; |
| 195 | StringInfo index; |
| 196 | int64 *u_index; |
| 197 | int32_t num_values,total_value_count; |
| 198 | SparseData sdata; |
| 199 | SvecType *result; |
| 200 | bits8 *bitmap; |
| 201 | int bitmask; |
| 202 | int i,j; |
| 203 | |
| 204 | /* Read in the two arrays defining the Sparse Vector, first is the array |
| 205 | * of run lengths (the count array), the second is an array of the |
| 206 | * unique values (the data array). |
| 207 | * |
| 208 | * The input format is a pair of standard Postgres arrays separated by |
| 209 | * a colon, like this: |
| 210 | * {1,10,1,5,1}:{4.3,0,0.2,0,7.4} |
| 211 | * |
| 212 | * For now, the data array must only have float8 elements. |
| 213 | */ |
| 214 | if ((values=strchr(str,':')) == NULL) { |
| 215 | ereport(ERROR, |
| 216 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 217 | errmsg("Invalid input string for svec"))); |
| 218 | } else { |
| 219 | *values = '\0'; |
| 220 | values = values+1; |
| 221 | } |
| 222 | /* Get the count and data arrays */ |
| 223 | pgarray_ix = DatumGetArrayTypeP( |
| 224 | OidFunctionCall3(F_ARRAY_IN,CStringGetDatum(str), |
| 225 | ObjectIdGetDatum(INT8OID),Int32GetDatum(-1))); |
| 226 | |
| 227 | pgarray_vals = DatumGetArrayTypeP( |
| 228 | OidFunctionCall3(F_ARRAY_IN,CStringGetDatum(values), |
| 229 | ObjectIdGetDatum(FLOAT8OID),Int32GetDatum(-1))); |
| 230 | |
| 231 | num_values = *(ARR_DIMS(pgarray_ix)); |
| 232 | u_index = (int64 *)ARR_DATA_PTR(pgarray_ix); |
| 233 | vals = (double *)ARR_DATA_PTR(pgarray_vals); |
| 234 | |
| 235 | /* The count and value arrays must be non-empty */ |
| 236 | int size1 = ARR_NDIM(pgarray_ix); |
| 237 | int size2 = ARR_NDIM(pgarray_vals); |
| 238 | if (size1 == 0 || size2 == 0) |
| 239 | ereport(ERROR, |
| 240 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 241 | errmsg("The count and value arrays must be non-empty"))); |
| 242 | |
| 243 | /* The count and value arrays must have the same dimension */ |
| 244 | if (num_values != *(ARR_DIMS(pgarray_vals))) |
| 245 | ereport(ERROR, |
| 246 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 247 | errmsg("Unique value count not equal to run length count %d != %d", num_values, *(ARR_DIMS(pgarray_vals))))); |
no test coverage detected