public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE){ // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); children = newChildren; } Object timeUnitValue = ((LiteralExpression)children.get(1)).getValue(); TimeUnit timeUnit = TimeUnit.getTimeUnit(timeUnitValue != null ? timeUnitValue.toString() : null); switch(timeUnit) { case WEEK: return new FloorWeekExpression(children); case MONTH: return new FloorMonthExpression(children); case YEAR: return new FloorYearExpression(children); default: return new FloorDateExpression(children); } }
public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE){ // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); children = newChildren; } Object timeUnitValue = ((LiteralExpression)children.get(1)).getValue(); TimeUnit timeUnit = TimeUnit.getTimeUnit(timeUnitValue != null ? timeUnitValue.toString() : null); switch(timeUnit) { case WEEK: return new FloorWeekExpression(children); case MONTH: return new FloorMonthExpression(children); case YEAR: return new FloorYearExpression(children); default: return new FloorDateExpression(children); } }
public static Expression create(List<Expression> children) throws SQLException { Expression firstChild = children.get(0); PDataType firstChildDataType = firstChild.getDataType(); if (firstChildDataType == PTimestamp.INSTANCE || firstChildDataType == PUnsignedTimestamp.INSTANCE){ // Coerce TIMESTAMP to DATE, as the nanos has no affect List<Expression> newChildren = Lists.newArrayListWithExpectedSize(children.size()); newChildren.add(CoerceExpression.create(firstChild, firstChildDataType == PTimestamp.INSTANCE ? PDate.INSTANCE : PUnsignedDate.INSTANCE)); newChildren.addAll(children.subList(1, children.size())); children = newChildren; } Object timeUnitValue = ((LiteralExpression)children.get(1)).getValue(); TimeUnit timeUnit = TimeUnit.getTimeUnit(timeUnitValue != null ? timeUnitValue.toString() : null); switch(timeUnit) { case WEEK: return new FloorWeekExpression(children); case MONTH: return new FloorMonthExpression(children); case YEAR: return new FloorYearExpression(children); default: return new FloorDateExpression(children); } }