예제 #1
0
  /** extracts index definitions as well */
  @SuppressWarnings("unchecked")
  private void internalExtractColumnDefinitions(
      ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
    if (propertiesMap == null) {
      return;
    }

    for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
      Map<String, Object> columnProperties = (Map) columnEntry.getValue();
      DataType columnDataType = getColumnDataType(columnProperties);
      ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());

      columnProperties = furtherColumnProperties(columnProperties);
      ReferenceInfo.IndexType columnIndexType = getColumnIndexType(columnProperties);
      if (columnDataType == DataTypes.OBJECT
          || (columnDataType.id() == ArrayType.ID
              && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
        ColumnPolicy columnPolicy = ColumnPolicy.of(columnProperties.get("dynamic"));
        add(newIdent, columnDataType, columnPolicy, ReferenceInfo.IndexType.NO, false);

        if (columnProperties.get("properties") != null) {
          // walk nested
          internalExtractColumnDefinitions(
              newIdent, (Map<String, Object>) columnProperties.get("properties"));
        }
      } else if (columnDataType != DataTypes.NOT_SUPPORTED) {
        List<String> copyToColumns = getNested(columnProperties, "copy_to");

        // extract columns this column is copied to, needed for indices
        if (copyToColumns != null) {
          for (String copyToColumn : copyToColumns) {
            ColumnIdent targetIdent = ColumnIdent.fromPath(copyToColumn);
            IndexReferenceInfo.Builder builder = getOrCreateIndexBuilder(targetIdent);
            builder.addColumn(
                newInfo(newIdent, columnDataType, ColumnPolicy.DYNAMIC, columnIndexType));
          }
        }
        // is it an index?
        if (indicesMap.containsKey(newIdent.fqn())) {
          IndexReferenceInfo.Builder builder = getOrCreateIndexBuilder(newIdent);
          builder
              .indexType(columnIndexType)
              .ident(new ReferenceIdent(ident, newIdent))
              .analyzer((String) columnProperties.get("analyzer"));
        } else {
          add(newIdent, columnDataType, columnIndexType);
        }
      }
    }
  }
예제 #2
0
  @Override
  public Object[] evaluate(Input[] args) {

    DataType innerType = ((ArrayType) this.info().returnType()).innerType();
    Set<Object> uniqueSet = new LinkedHashSet<>();
    for (Input array : args) {
      if (array == null || array.value() == null) {
        continue;
      }
      Object[] arg = (Object[]) array.value();
      for (Object element : arg) {
        uniqueSet.add(innerType.value(element));
      }
    }

    return uniqueSet.toArray();
  }
  public static PartitionName toPartitionName(
      TableIdent tableIdent,
      @Nullable DocTableInfo docTableInfo,
      List<Assignment> partitionProperties,
      Object[] parameters) {
    if (docTableInfo != null) {
      return toPartitionName(docTableInfo, partitionProperties, parameters);
    }

    // Because only TableIdent is available, types of partitioned columns must be guessed
    Map<ColumnIdent, Object> properties = assignmentsToMap(partitionProperties, parameters);
    BytesRef[] values = new BytesRef[properties.size()];

    int idx = 0;
    for (Map.Entry<ColumnIdent, Object> entry : properties.entrySet()) {
      DataType guessedType = DataTypes.guessType(entry.getValue(), false);
      Object value = guessedType.value(entry.getValue());
      values[idx++] = DataTypes.STRING.value(value);
    }
    return new PartitionName(tableIdent, Arrays.asList(values));
  }
예제 #4
0
 private ImmutableMap<ColumnIdent, String> getAnalyzers(
     ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
   ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder();
   for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
     Map<String, Object> columnProperties = (Map) columnEntry.getValue();
     DataType columnDataType = getColumnDataType(columnProperties);
     ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
     columnProperties = furtherColumnProperties(columnProperties);
     if (columnDataType == DataTypes.OBJECT
         || (columnDataType.id() == ArrayType.ID
             && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
       if (columnProperties.get("properties") != null) {
         builder.putAll(
             getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties")));
       }
     }
     String analyzer = (String) columnProperties.get("analyzer");
     if (analyzer != null) {
       builder.put(newIdent, analyzer);
     }
   }
   return builder.build();
 }
예제 #5
0
    @Override
    public FunctionImplementation<Function> getForTypes(List<DataType> dataTypes)
        throws IllegalArgumentException {
      Preconditions.checkArgument(
          dataTypes.size() >= 1 && dataTypes.size() <= 2,
          "array_unique function requires one or two arguments");

      for (int i = 0; i < dataTypes.size(); i++) {
        Preconditions.checkArgument(
            dataTypes.get(i) instanceof ArrayType,
            String.format(
                Locale.ENGLISH,
                "Argument %d of the array_unique function cannot be converted to array",
                i + 1));
      }

      if (dataTypes.size() == 2) {
        DataType innerType0 = ((ArrayType) dataTypes.get(0)).innerType();
        DataType innerType1 = ((ArrayType) dataTypes.get(1)).innerType();

        Preconditions.checkArgument(
            !innerType0.equals(DataTypes.UNDEFINED) || !innerType1.equals(DataTypes.UNDEFINED),
            "One of the arguments of the array_unique function can be of undefined inner type, but not both");

        if (!innerType0.equals(DataTypes.UNDEFINED)) {
          Preconditions.checkArgument(
              innerType1.isConvertableTo(innerType0),
              String.format(
                  Locale.ENGLISH,
                  "Second argument's inner type (%s) of the array_unique function cannot be converted to the first argument's inner type (%s)",
                  innerType1,
                  innerType0));
        }
      } else if (dataTypes.size() == 1) {
        DataType innerType = ((ArrayType) dataTypes.get(0)).innerType();
        Preconditions.checkArgument(
            !innerType.equals(DataTypes.UNDEFINED),
            "When used with only one argument, the inner type of the array argument cannot be undefined");
      }

      return new ArrayUniqueFunction(createInfo(dataTypes));
    }